Enabling GZIP Compression on Dreamhost

October 15 2008, 12:11am

EDIT: So I talked to Toby Miller and he helped clarify some issues I was having - the script has been updated below!

So I’ve been discussing compression - I’m a fiend for it. It’s like a drug to me. I squeeze every byte out of production code. I’d compress HTML into a single line - I’m just that phucked up. Maybe it’s my OCD, maybe I’m just nutty, but GZIPping seems like a no brainer to me. 1-2-3 COMPRESS! What’s GZIP? I’m glad you asked, friend! According to the never-wrong wikipedia article on GZIP: gzip is a software application used for file compression. gzip is short for GNU zip; the program is a free software replacement for the compress program used in early Unix systems, intended for use by the GNU Project. What this basically does is compress your files and let the client unzip them. We’re talking about massive decreases in bandwidth, so that 200k website suddenly shrinks down. No More Optimizing, YAY! NO NO NO! I’m sorry friend, but GZIP is not an excuse to get lazy. You can use GZIP on Javascript Frameworks so that compressed 60k core file can become a 15k file. Wow. Just take that in. 75% reduction of an already compressed file! That’s awesome. 101k html text file can be compressed to 15k. Frickin’ badass. So naturally, why wouldn’t I want to enable this on my Dreamhost sites? The GZIP Code Please note: As I’m using Apache2, we’re calling mod_deflate instead of mod_gzip. I’ve added this to my .htaccess files:

BEGIN GZIP

<ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule>

END GZIP

Danger, Will Robinson! Naturally, their are a few caveats from GZIP, as better explained by BetterExplained.com (heh):

Older browsers: Yes, Virginia, no doubt you may be asked to support crappy browsers. We’re talking old-school-extreme, like Netscape 1.0 on Windows 95. Apache mod_deflate has some rules to avoid compression for older browsers. Already-compressed content: As BetterExplained.com details, you probably only need to compress the “big 3″ (HTML, CSS and Javascript) as images/flash/etc are usually already compressed. Usually. CPU-load: Compressing content on-the-fly uses CPU time and saves bandwidth. Usually this is a great tradeoff given the speed of compression. There are ways to pre-compress static content and send over the compressed versions. This requires more configuration; even if it’s not possible, compressing output may still be a net win. Using CPU cycles for a faster user experience is well worth it, given the short attention spans on the web.

So enjoy the benefits friends, pass on the glory of GZIP! Copyright © 2008 iKeif - tech and social media geek, mootools fan, and a ton of links. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@ikeif.net so we can take legal action immediately.Plugin by Taragana