Posted by Neil Crosby on February 19, 2008 11:19 AM
I’ve known about the benefits that gzipping the content on my sites would give me for quite some time (files are zipped up as they travel to your users, making them faster to download and leaving you with a smaller bandwidth bill), but I never got around to enabling it because, well, I’m lazy.
It’s really easy to set up things on your server to automatically gzip all sensible files though, and most of the code you need is very easily found in the Apache 2 documentation. All you have to do is copy and paste the following into your .htaccess file, and all your files (except images) will end up being gzipped for you. Awesome.
<IfModule mod_deflate.c> # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0 no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 # the above regex won't work. You can use the following # workaround to get the desired effect: BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </ifModule>
In my tests I’ve seen a 70-80% drop in over the wire weight for those gzipped files. Not too shabby at all.
My advice? Whack that code somewhere in your .htaccess file and watch your bandwidth usage plummet like a stone.
If you really enjoyed what you just read, why not buy yourself something from Amazon? You get something nice for yourself, and I get a little bit of commission to pay for servers and the like. Everyone's a winner!
TrackBack URL for this entry: http://www.workingwith.me.uk/cgi-bin/type/mt-tb.cgi/785