Website compression should i?

Website compression is an important feature which can help increase a websites loading speed, before you dive straight in you need to understand how it works as it will increase CPU usage which could lead to a web server (especially busy ones) becoming slow resulting in slow website speeds (which could leave you with a website which now loads even slower than with no compression).

On demand v precompressed content
When enabling compression such as apaches deflate or gzip the content is compressed on the fly meaning that when a visitor requests a page all the content related to that page is compressed at that very moment and then sent to the client, what this means is that with every page load the CPU is recompressing the content for each client. This has its positives and negatives such as stale content (dynamic pages) is never sent to the clients browser but the server has to do compression with every request and on a busy server this can lead to a stall as the CPU can’t process the compression requests faster than it is receiving them.
Precompressed content also known as caching has its benefits as the server compresses the content once and then stores it into a cache location, anymore requests for any files which have already been cached will be loaded from the cache so the server doesn’t have to recompile, the major issue with caching content is that dynamic page will not work correctly if loaded from the cache, what this means is that stale content (old versions of a page) will be sent to the client which can lead to website features not working such as login pages.

Knowing what to compress
You must understand is what types of files and data you can compress, it is quite common to find that people enable website compression and just compress everything what this does is increase CPU and potentially loading speed which is not necessary as the data is already compressed. Allot of data on a website is already stored in a compressed format such as images and archive files, file formats such as zip, rar, jpg, png and gif are already stored in a compressed format and so recompressing an already compressed file doesn’t adjust its size greatly (you are talking about a couple of KB maybe a couple of MB on a huge file). All you will be doing is putting extra unneeded stress onto the CPU which on a busy server will slow the overall performance of the server. If your images, videos or archive files are large you should find alternative ways to lower their size such as decreasing the bitrates, audio quality, image quality, scale and various other options. You should read my post here related to oversized images.

Is my website already compressed?
It is simple to detect if your website is being compressed via various methods, one of the most simplest it to use a gzip testing website such as http://www.gidnetwork.com/tools/gzip-test.php, this website will simply tell you if your website is being sent compressed and if not estimate the total size if it was to be compressed. If you are to view the header data of your website response it will include a compression line if there isn’t one then compression isn’t enabled. You may need to use an add-on such as Live HTTP Headers for Firefox to view the header data.

Should I or shouldn’t I?
Compression does have its benefits but it comes with risks as well I personally use it myself but I have tested it rigorously on my server and have a CPU usage monitor installed, this allows me to keep an eye on the CPU usage and if it was to ever go to high from a sudden burst of traffic I will know and can disable or decrease the compression level. One thing is for sure that I would never enable compression on a live server unless I know for defiantly that the server can handle the extra load, I have seem numerous times people saying there server is struggling and the CPU is dying but as soon as compression is disabled it goes from performing like a school bus to a Ferrari almost instantly. Yes the benefits can be great but you must and i mean must test it first especially if it’s an already busy server.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.