Agile Web Development

Build it. Launch it. Love it.


JavaScript and CSS Asset Compression for Production Rails Apps


When it comes time to deploy your new web application, instead of sending down a dozen javascript and css files full of formatting and comments, this Rails plugin makes it simple to merge and compress JavaScript and CSS down into one or more files, increasing speed and saving bandwidth.

When in development, it allows you to use your original versions and retain formatting and comments for readability and debugging.

Because not all browsers will dependably cache javascript and css files with query string parameters, AssetPackager writes a timestamp or subversion revision stamp (if available) 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.

This code is released under the MIT license (like Ruby). You’re free to rip it up, enhance it, etc. And if you make any enhancements, I’d like to know so I can add them back in. Thanks!


This Rails Plugin was inspired by Cal Henderson’s article "Serving Javascript Fast" on Vitamin:

It also uses the Ruby Javascript Minifier created by Douglas Crockford.

Key Features

  • Merges and compresses javascript and css when running in production.
  • Uses uncompressed originals when running in development.
  • Handles caching correctly. (No querystring parameters - filename timestamps)
  • Uses subversion revision numbers instead of timestamps if within a subversion controlled directory.
  • Guarantees new version will get downloaded the next time you deploy.


  • Rake Task for merging and compressing javascript and css files.
  • Helper functions for including these javascript and css files in your RHTML.
  • YAML configuration file for mapping javascript and css files to merged versions.
  • Rake Task for auto-generating the YAML file from your existing javascript and css files.


License Rails' (MIT)
Rating (18 votes)
Owner Scott Becker
Created 19 June 2006


Add a comment