The module used for configuring gzip depends on your version of Apache: Apache 1.3 uses mod_gzipwhile Apache 2.x usesmod_deflate. This section describes how to configure each module, and focuses on Apache because it is the most popular web server on the Internet.
Apache 1.3: mod_gzip
Gzip compression for Apache 1.3 is provided by the mod_gzipmodule. There are manymod_gzipconfiguration directives, and these are described on themod_gzipweb site (http://www.schroepl.net/projekte/mod_gzip). Here are the most commonly used directives:
mod_gzip_on Enables mod_gzip.
mod_gzip_item_include mod_gzip_item_exclude Define which requests to gzip or not to gzip based on file type, MIME type, user agent, etc.
Most web hosting services havemod_gzipturned on fortext/html by default. The most important configuration change you should make is to explicitly compress scripts and stylesheets. You can do this using the following Apache 1.3 directives:
The gzip command-line utility offers an option that controls the degree of compression, trading off CPU usage for size reduction, but there is no configuration directive to control the compression level inmod_gzip. If the CPU load caused by streaming compression is an issue, consider caching the compressed responses, either on disk or in memory. Compressing your responses and updating the cache manually adds to your maintenance work and can become a burden. Fortunately, there are options formod_gzipto automatically save the gzipped content to disk and update that gzipped content when the source changes. Use themod_gzip_can_negotiateand mod_ gzip_update_staticdirectives to do this.
Apache 2.x: mod_deﬂate
Compression in Apache 2.x is done with the mod_deflatemodule. Despite the name of the module, it does compression using gzip. The basic configuration shown in the previous section for compressing scripts and stylesheets is done in one line:
Unlikemod_gzip,mod_deflatecontains a directive for controlling the level of compression:DeflateCompressionLevel. For more configuration information, see the Apache 2.0mod_deflatedocumentation at http://httpd.apache.org/docs/2.0/mod/mod_ deflate.html.