I have a Rails app using the Rails javascript helpers to concat all the javascript together into a single file.

In addition my web server is serving this javascript file to the end users as gzip compressed.

As modern browsers will request the compressed version - is there any real benefit to me bothering to minify the javascript on each deploy? I'm sure it will save some bandwidth but will it be worth it if the content was already compressed.


That depends on your definition of "worth it" is, obviously. I have a rather large JS file in a project:

  • Original state: 41.7 kB
  • Minimized with YUI compressor: 27.8 kB (~67% of non-minimized)
  • Non-minimized, gzipped (with 7-zip/"normal" compression level): 10.8 kB (~26% of original)
  • Minimized and gzipped: 7.45 kB (~18% of original, ~69% of gzipped/non-minimized)

YMVV, but as we see, the relative size of a minimized to a non-minimized file is about the same even after gzipping (approximately two thirds). I balanced those 3 kBs I'd gain by minimizing against the weight of the rest of the page (== considerable), and decided against bothering with minimization.

Minimization does give your developers an advantage, though - as it strips out comments, you sprinkle the code with bug notices, explanations for kludges or complaints about stupid customers, lusers, management, etc, without risking embarrassment if someone does a View Source.

  • Actually, I checked and with minification I reduced my JS from 180k/61.5k (uncompressed/compressed) to 101k/37k. I figure a 25k saving is probably worth it overall for the hour it took me to get minification running on deploy. Aug 20 '09 at 11:34

Also, minimification helps when there is a user coming to your site through a proxy, as that sometimes prevents the use of GZIP compression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.