Get More Out of Your Pipe with Apache and mod_gzip
It's never bad to give your users a faster site. With mod_gzip and Apache, you can compress Web traffic on the fly, reducing file sizes (and download times) up to 80 percent.
Some Web sites seem like they are designed to annoy and alienate visitors. Teeny tiny fixed fonts, weirdo fixed page widths, ad servers on Mars, and the content won't load until the ads do, and all kinds of dynamic jiggery-pokery that does everything but quickly deliver a nice, readable page.
Webmasters who are serious about running high-performance Web servers, and who want pleased and delighted visitors, have a great tool in Apache 1.3's mod_gzip. mod_gzip compresses pages on the fly, reducing their size considerably. Depending on the types of files served, you'll see size reductions ranging from 20%- 80%, and a nice increase in server efficiency. Nothing is needed on the client side, except sane modern Web browsers like Mozilla, Firefox, Opera, Galeon, and Konqueror. Mozilla, Firefox, and Opera are nice cross-platform browsers with all kinds of neat features, so don't be afraid to standardize on one of them. You won't be sorry. Internet Explorer more or less supports mod_gzip, but some file formats, such as .pdf, don't always render correctly, and it's a big security hole anyway. You'll want to check out the Resources section below for links that clarify some of the issues assorted browsers have with gzipped content.
mod_gzip compresses static files, and any CGI-generated pages. You'll get the same results as using gzip on any file: Files that are already highly-compressed, like .jpg, won't compress much further, and text files will shrink a lot.
It's Not Magic
But good smart design and coding. When Josephine Surfer wanders to your Web site, Apache checks the headers sent by her Web browser and looks for the "Accept-encoding: gzip" HTTP request header. Apache smiles, and sends some headers in return: Content-Type: text/html and Content-Encoding: gzip. Josephine's Web browser now knows that it will receive nice lean gzipped pages, and must expand them as HTML pages.
You, the ace Webmaster, define in httpd.conf exactly which mime types and file types will be gzipped, and there are a whole lot of them. See the Configuration section below.
mod_gzip is available in the usual package formats, and source tarballs. If your particular package does not include bales of documentation, including HTML docs and a well-commented sample configuration file, get the tarball. It's only 415 kilobytes, a small price to pay to get the good documentation.
To build mod_gzip from sources, first edit the Makefile, giving it the path to the apxs file on your system. Usually this is /usr/bin/apxs. (Debian users, you'll need the apache-dev package to get this file.) It's the first line in the file:
Change this to
$ make # make install