Even though minification does no harm and is relatively easy to implement, it is worthwhile to ask a basic question: how much does it really help?
Using the database from the HTTP Archive’s July 1, 2011 run, I conducted an experiment:
- Fetch, via HTTP, every CSS document listed in the archive. (The selection criteria used to obtain a list of CSS URLs from the archive’s
status=200 and (resp_content_type="text/css" or resp_content_type like "text/css;%").)
- Upon retrieving each CSS document, use YUI Compressor to minify it, and record the pre- and post-minification sizes.
- Using “
gzip -6,” compress the pre- and post-minified forms of the CSS document to measure the effects of minification in combination with compression.
A small number of URLs that resulted in unusable data, due to a problem in the fetch script’s handling of servers that returned gzipped content in response to requests without an Accept-Encoding. With these URLs excluded, 64,470 CSS URLs remained in the data set.
The 50th percentile benefit observed from applying minification was:
- 17.9% reduction in the uncompressed CSS file size
- 13.9% reduction in the compressed CSS file size
The following graphs show the distribution of minification benefit, from no benefit at the 0th percentile (corresponding to CSS files that were already minified) to a 100% reduction in download size at the other end of the scale (corresponding to CSS files that contained nothing but comments and/or whitespace).
Based on the data from this experiment, most websites could decrease their total CSS download size measurably by implementing CSS minification.