MergeJS
= MergeJs
Now superceded by AssetPackager which supports CSS as well. See: http://www.agilewebdevelopment.com/plugins/assetpackager
Easily merge, compress, cache, and version your javascript with Ruby on Rails!
IntroductionWith the sudden overwhelming desire we web developers feel to write AJAX apps, JavaScript has suddenly jumped to the forefront of our work. The amount of javascript files in our applications is proliferating with no end in sight.
We feel a pang of regret each time we create a new one, knowing we just added one more HTTP request for our end-users, and thus an increase in load time.
OH NO!!! WHAT TO DO???
Wouldn't it be nice to logically separate our JavaScript files into small, meaningful chunks without an extra request to the server for each one? Now you can!
DescriptionWhen running in production, instead of sending down a dozen javascript files full of formatting and comments, this plugin allows you to merge and compress javascript down into one or more files, thus saving download time for your users.
But when in development, it would be nice to use the formatted, commented and logically separated versions for ease of development and debugging.
This plugin makes it easy to do both.
Because not all browsers will dependably cache javascript files with query string parameters, we write a datetime stamp into the merged file names. Therefore files are correctly cached by the browser AND your users always get the latest version when you re-deploy!
CreditThis Rails Plugin was inspired by Cal Henderson's article "Serving Javascript Fast" on Vitamin: http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
It also uses the Ruby Javascript Minifier created by Douglas Crockford. http://www.crockford.com/javascript/jsmin.html
Key Features- Merges and compresses javascript when running in production.
- Uses uncompressed originals when running in development.
- Handles caching correctly on all browsers. (No querystring parameters – filename timestamps)
- Guarantees new version will get downloaded the next time you deploy.
== Components
- Rake Task for merging and compressing javascript files.
- Helper function for including these javascript files in your RHTML.
- YAML configuration file for mapping javascript files to merged versions.
- Rake Task for auto-generating the YAML file from your existing javascript files.
- Repository Path: http://sbecker.net/shared/plugins/merge_js
- Homepage: http://synthesis.sbecker.net/pages/merge_js