Eric Lawrence posted an article the other day on web compression, focusing a bunch of different algorithms, what should get compressed and how to get the best performance on your site based on mixing minification and compression. It’s a great read with lots of good, useful information.
Isn’t compression used on most sites already?
This got me curious of the state of compression on the web. How many sites use some form of compression? My initial assumption was > 90%, but even that sounded low. I looked up some stats on W3Techs, which provides “information about the usage of various types of technologies on the web.” Based on their studies, they found that:
Compression is used by 58.1% of all the websites.
Fifty-eight point one percent.
That’s it? I was astounded when I first read that number and I’m still pretty surprised now. There are estimated to be over 1 billion websites in existence right now, which means 500 million of them are sending uncompressed data. That’s a lot of useless bytes being sent through the wire.
It makes no sense to not enable compression. It’s incredibly easy to set up in both Apache and IIS (on IIS you seriously just have to click a few buttons). Enabling it will only affect users for the good, because not only have all major browsers supported it for the past ~10 years, they all send the
Accept-Encoding: gzip header if they support compression. If they don’t send the header, the server won’t compress the response. Everyone gets their content either way, some will just get it faster than others.
The only downside is a slight increase in CPU usage, but that is a minimal increase for a massive decrease in response size. To show how much the response size is decreased, we can use the Composer in Fiddler to run two requests to http://davidzych.com, one with the
Accept-Encoding: gzip header and one without:
|Without Compression||With Compression (gzip)||Savings|
|79,203 bytes||21,499 bytes||72.8%|
Multiply that over thousands of users a month and that’s a significant bandwidth savings.
Compress yourself before your wreck yourself
- Read Eric Lawrence’s post about compression
- Enable compression on your Apache or IIS server
- Make sure you only compress data that needs it – most images (jpg, png, gif) are already compressed and any type of small file could actually be larger when compressed.
Your server’s internet pipes will thank you.