An explanation and code example for using mod_gzip or mod_deflate to make web pages smaller and load faster in Apache 1 and Apache 2.
OrangeCoat enables compression because it reduces bandwidth, reduces wait time for visitors, it's fairly easy to setup, and it's one of YSlow's main performance factors. Usually the compressed files are 1/3 to 1/4 of their original size.
All modern web browsers should support gzip and deflate. The browser simply tells the web server to compress parts of the web page before they are sent. Then, the browser handles un-compressing them. Since internet speeds are the bigger bottleneck it usually makes sense to have the server and browser burn extra CPU time in order to reduce the bandwidth required to download a page.
The YSlow plug-in is very helpful for checking what, if anything, is being compressed. Look at the Components tab of YSlow and look for "gzip" under the Gzip column. It will also show how much the files are being compressed.
Example of YSlow gzip Results
Add the following to your http.conf (within the main body, or inside of a VirtualHost directive) or to your .htaccess . This example is for the mod_gzip module, assuming it's already installed and enabled.
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader Content-Type:image/*
mod_gzip_item_include file \.js$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$
If you find mod_gzip is not installed it can be manually installed as a DSO without recompiling Apache.
For Apache 2 the mod_deflate module has taken over in place of mod_gzip. The directives are quite different. It's possible to use either inclusive or exclusive settings. Below is an example of inclusive. Add the following to your http.conf (within the main body, or inside of a VirtualHost directive) or to your .htaccess
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Mod_deflate should be installed and enabled. If not, you may need to enable or install mod_deflate.