Since we like to keep as much of our code as possible in the Ruby family, we use the Ruby version of the minifier. Copy The jsmin.rb file to script/javscript/jsmin.rb in your Rails application.
libs array as needed, or adjust what you want the final file to be named. Then copy the code into a file named lib/tasks/js.rake.
Before we run the task, there is a single point in Prototype version 1.5 stable that breaks the jsmin filter. There is a patch for this in the Rails trac, but we will need to manually add the single missing semi-colon until it is applied. You may want to also run your application code through JSLint Verifier and clean up any issues that may jam the jsmin filter.
You’ll have to make sure to run this rake task before you deploy, and may want to add it directly to your deployment script.
Update – 03/01/2007
Prototype doesn’t actively support a specific packing strategy for various reasons, and patches submitted for making the code pass something like JSLint are likely to be ignored. Reasons for this, and some other strategies on reducing filesize of the library are discussed in Packing Prototype.
Update – 12/14/2007
Rails 2.0 includes a feature that makes much of what is described here obsolete. Check out our write-up of Rails Asset Cache.
Sorry, the comment form is closed at this time.