GZIP Compression in a Nutshell

I finally have had some time to wrap my head around a number of lingering topics lately one of them being GZIP Compression. When the client (your browser) requests a page from a web server it sends along HTTP headers with the request, one of the header fields includes Accept Encoding: which tells the web server what HTTP compression formats it is willing to accept when the server responds.

Most modern browsers are able to accept GZIP, deflate which allows the server to fetch the requested document and compress it before sending it back to the client, where it is then essentially uncompressed on the client (your browser) side. This reduces both load time and bandwidth. Seems like a win win situation to me, considering how instantaneous users are expecting to see and be able to interact with your pages.

Sample Implementation to include in your .htaccess file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

This compression method along with concatenating and minifying scripts and css files, should be used on all HTML,CSS, and JavaScript files. Most images have some type of compression already on them so its not as big of a deal to worry about them so much using this technique.  Further research and explanation on implementation can be found  here.

Leave a Reply