Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manage your Javascript files?

Tags:

Nowadays, we have tons of Javascript libraries per page in addition to the Javascript files we write ourselves. How do you manage them all? How do you minify them in an organized way?

like image 842
danmine Avatar asked Oct 20 '08 17:10

danmine


People also ask

Where should I store JavaScript files?

JavaScript in body or head: Scripts can be placed inside the body or the head section of an HTML page or inside both head and body. JavaScript in head: A JavaScript function is placed inside the head section of an HTML page and the function is invoked when a button is clicked.

How do I reduce the number of JavaScript files?

Combine all JavaScript files in one file To minimize the number of HTTP requests you should try combining the content of all your JavaScript files to one bigger file. This isn't always possible with every JavaScript file, though. Try and see how it works out for your site.

Can I delete JavaScript files?

You can probably delete the javascript files, but it depends on whether they are custom scripts for your project, or the general Robohelp (RH) ones. It has been a few years since I upgraded and things could have changed. RH script files began with ehlp*.


2 Answers

Organization

All of my scripts are maintained in a directory structure that I follow whenever I work on a site. The directory structure normally goes something like this:

+--root    |--javascript       |--lib          |--prototype.js          |--scriptaculous             |--scriptaculous.js             |--effects.js             |--..       |--myOwnScript.js       |--myOwnScript2.js 

If, on the off chance, that I'm working on a team uses an inordinate amount of scripts, then I'll normally create a custom directory in which we'll organize scripts by relationship. This doesn't happen terribly often, though.

Compression

Though there are a lot of different compressors and obfuscators out there, I always come back to YUI Compressor.

Inclusion

Unless a site is using some form of a master page, CMS, or something that dictates what can be included on a page beyond my control, I only included the scripts necessarily for the given page just for the small performance sake. If a page doesn't require any script, there will be no script inclusions on that page.

like image 119
Tom Avatar answered Sep 29 '22 14:09

Tom


First of all, YUI Compressor.

Keeping them organized is up to you, but most groups that I've seen have just come up with a convention that makes sense for their application.

It's generally optimal to package up your files in such a way that you have a small handful of packages which can be included on any given page for optimal caching.

You also might consider dividing your javascript up into segments that are easy to share across the team.

like image 40
keparo Avatar answered Sep 29 '22 15:09

keparo