Call (877) SITE-OPT (748-3678)

Code: Configuring mod_gzip

Chapter 9 - Advanced Web Performance Optimization

Here is an example addition to an httpd.conf configuration file:

# Dynamic Shared Object (DSO) Support
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding 'LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Please read the file for more
# The order in which these modules load is important...
LoadModule rewrite_module libexec/
LoadModule expires_module libexec/
LoadModule php4_module libexec/
LoadModule bwlimited_module libexec/
LoadModule bytes_log_module libexec/
LoadModule auth_passthrough_module libexec/
LoadModule gzip_module libexec/
# ...
# Reconstruction of the complete module list from all available modules
# (static and shared ones) to achieve correct module execution order.
AddModule mod_env.c
AddModule mod_php4.c
AddModule mod_bwlimited.c
AddModule mod_log_bytes.c
AddModule mod_auth_passthrough.c
AddModule mod_gzip.c

Note how LoadModule and AddModule mod_gzip are the last commands in the list. Next, configure mod_gzip with the minimum file size (anything less than 1,000 bytes is not worth the overhead), the maximum in-memory size directive (we chose 1,000,000 bytes as a maximum), and the types of files to include in compression:

<IfModule mod_gzip.c>
mod_gzip_on yes
mod_gzip_send_vary yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_temp_dir /tmp
mod_gzip_minimum_file_size 1002
mod_gzip_maximum_file_size 0
mod_gzip_maximum_inmem_size 1000000
mod_gzip_item_include file "\.htm$"
mod_gzip_item_include file "\.html$"
mod_gzip_item_include mime "text/.*"
mod_gzip_item_include file "\.php$"
mod_gzip_item_include mime "jserv-servlet"
mod_gzip_item_include handler "jserv-servlet"
mod_gzip_item_include mime "application/x-httpd-php.*"
mod_gzip_item_include mime "httpd/unix-directory"
mod_gzip_item_exclude file "\.css$"
mod_gzip_item_exclude file "\.js$"
mod_gzip_item_exclude file "\.wml$"

Note that we include text, .htm/.html, and .php files but exclude .css, .js, and .wml files to simplify this example. Do not HTTP-compress MP3 files (because they are already compressed), or PDF files (Acrobat Reader can have problems reading gzipped PDF files because they are already compressed internally).

Copyright © 2002-2017 Website Optimization, LLC. All Rights Reserved - Free website speed test - Privacy Policy
Last modified: February 19, 2009.

Follow us on: Twitter, Google+, Facebook, Linked In