Plugins - MergeJS
Add to favoritesMergeJs
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!
Introduction
With 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!
Description
When 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!
Credit
This 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.
http://synthesis.sbecker.net/pages/merge_js
http://sbecker.net/shared/plugins/merge_js
Rails' (MIT)
Assets

It now supports the rails AssetHost property as well as the relative url root.
For an AssetHost, add to environment.rb: ActionController::Base.asset_host = “http://assets.example.com�
For a different root url, add to environment.rb: ActionController::AbstractRequest.relativeurlroot = �/dir�
Has this been tested with running a seperate assets server or serving the javascript out of the rails stack such as with Lighttpd?