Friday, June 6, 2008

Optimizing JavaScript in Ruby on Rails

posted by Jonah Dempcy

I'm learning Ruby on Rails for a current client of mine, and wanted to share this tip on how to optimizing JavaScript performance in Ruby on Rails. This will only focus on one aspect of JS performance optimization, namely, writing a build script to concatenate/minify the JS, and setting up Rails to easily toggle between the compressed and normal files.

The reason to do this is that it's faster for the client to download one file, compared to multiple files. In other words, 10 1-kilobyte files are much slower to download than a single 10k file. You might not think it makes much of a difference, but I estimate that removing 10 additional JS files, for instance, will shave 500-1000ms off latency. Plus, all of the time spent loading the JS will leave the page blank, if you put it in the head.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home