Effects of GZipping vs. minifying HTML files
Last time we took a look at the performance impact of using tabs vs. spaces in HTML files. One question that arose was whether or not it’s worthwhile to minify HTML when also using GZip. Let’s run the experiment.
I’ve collected a few real-world HTML files and done some minification and GZipping on them. Here’s the result:
Website | File size | Minified | Gzip | GZip & minified | Savings |
---|---|---|---|---|---|
amazon.com | 218,642 | 197,032 | 53,793 | 49,008 | 9% |
cnn.com | 130,014 | 121,534 | 27,114 | 25,392 | 6% |
twitter.com | 53,465 | 46,608 | 12,262 | 11,416 | 7% |
xbox.com | 38,888 | 24,139 | 8,075 | 6,795 | 16% |
These pages already do minification on various sections, but none of them minifies the whole document. If none of them used any minification, the savings would have been higher than the table shows.
So, according to the results, minification will provide an additional 6-16% lower file size with GZip enabled.
16% is a rather large saving on top of regular GZip, so the data suggests that we must use both GZip AND minification.
Remember, this is a rather small experiment with only 4 real-world websites. It would be interesting to expand the experiment for more accurate statistics.
For HTML minification in ASP.NET, I like to use WebMarkupMin or Meleze.Web.