In some cases, a minifier will actually increase the size of a script, in particular with small scripts if the minifier has some constant overhead, such as might be encountered to process variable name tranformations. To avoid unnecessarily skewing our data with these cases, we emulated an intelligent minifier that tests to see whether the post-minified output is smaller than the base script, and if not, it emits the untransformed script. Similarly, for the analysis of the gzipped(minified) set, we emulated an intelligent tool that emits the smallest of (a) the untransformed script, (b) the minified script, (c) the gzipped script, or (d) the gzipped + minified script.
How often does minification help?
|number of scripts|
the minifier shrunk
|percent of scripts|
the minifier shrunk
For most minifiers, minification was effective across virtually all scripts. However, the packer minifier only deflated 66% of scripts; the other 34% grew larger. This is because packer emits a constant overhead preamble to minified scripts, and in the case of small (roughly 100 byte or less) scripts, the benefits from minification did not outweigh the cost of this constant overhead. Click here to explore an example.
How many bytes are saved using minification and gzipped(minification)?
gzipping alone was quite effective, compressing away 71% of bytes. Individual minifiers fare worse than gzip alone, saving between 48% and 70% of bytes, with packer being the most effective, in spite of its ineffectiveness for small scripts.
Interestingly, however, the combination of gzipping and minification does best, and Google's closure compiler seems to be most amenable to gzipping. closure has a slight advantage over the other minifiers when combined with gzip, saving 81% of transmitted bytes. gzipped(closured) scripts were reduced another 34% compared to gzipped scripts alone.
Overall, then, enabling gzip-compressed content encoding on web servers will produce substantial savings, but there are still substantial improvements that can be gained with gzipped minification.
How do the different minifiers stack up?
To answer this question, we calculated the distribution of reduction factors for each minifier across the pages of the corpus. If a script is X bytes long, and post-minification it is Y bytes, then we define the reduction factor to be Y/X. So, smaller numbers mean more effective minification, and a number less than one implies that minification reduced the script size. Since we're using our intelligent minifiers, the worst-case reduction factor we will see is 1.0.
The following charts show these distributions across the minifiers, and across the gzipped(minified) combinations. Most minifiers seem similar, except that packer fares badly on small scripts while closure and perhaps yui do best overall. As previously described, in the vast majority of cases gzip improves post-minification script sizes.
For related studies, see: