Configuration
The module used for configuring gzip depends on your version of
Apache: Apache 1.3 uses mod_gzip
while Apache 2.x uses mod_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_gzip
module. There are many mod_gzip
configuration directives, and these
are described on the mod_gzip
web
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 have mod_gzip
turned on for text/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:
mod_gzip_item_include file \.js$ mod_gzip_item_include mime ^application/x-javascript$ mod_gzip_item_include file \.css$ mod_gzip_item_include mime ^text/css$
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
in mod_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 ...
Get High Performance Web Sites now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.