Skip to main content
DamienG
Code editor beside a diagram of connected services and databases

Rick Strahl has a post on a JavaScript minifier utility the sole job of which is to shrink the size of your JavaScript while making it almost impossible to read in order to save a few kilobytes. I thought I’d take a quick look at what the gain would be and fed it the latest version (1.6) of the very popular Prototype library:

File (KB) GZip (KB)
Standard 121.0 26.7
Shrunk/minified 90.5 22.0
Saving 30.7 4.7

The 30.7 KB saving looks great at first glance but bear in mind that external JavaScript files are cached on the client between page requests and it loses some appeal. If you also consider the fact that most browsers and clients support GZip compression and the savings there are around 4.7 KB and you might wonder if you are wasting your time. In computer science there is a term for blindly attempting to optimise systems without adequate measurement or justification and that term is premature optimisation. As Sir Tony Hoare wrote (and Donald Knuth paraphrased)

We should forget about small efficiencies, say about 97% of the time: premature optimisation is the root of all evil.

And he was working on computers throughout the 60s and 70s that had much less resources than those today. By all means if your server bandwidth is an issue delve into the stats, identify the cause and take it from there. Going with Yahoo’s YSlow plug-in for Firefox/Firebug is a great starting point but remember to analyse the statistics from your own context.

Rick’s tool had shortcomings with non-ASCII characters such as accents, symbols and non-US currency symbols which goes to show how optimisation can have other unintended and undesirable effects.

[)amien

0 responses

  1. Information is only used to show your comment. See my Privacy Policy.