mod_deflatemod_deflate overviewmod_deflate module applies DEFLATE filter that allows server output to be compressed before sending it to the client over the network. Examples of mod_deflate implementationCompress only specific types
Compress everything except images
Enabling CompressionOutput Compression Compression is enabled by DEFLATE filter as follows:
Some browsers do not support compression of all content types, so you may need to set gzip-only-text/html to 1 to only allow compression of html files. If you put other value than 1, it will be ignored. If you want to restrict the compression to particular MIME types, you may use AddOutputFilterByType directive:
For those browsers that have problems with compression of all file types it may be helpful to use BrowserMatch directive to force no-gzip for that particular browsers. You may combine no-gzip with gzip-only-text/html to get the best results. In that case the former overrides the latter:
At first we probe for a User-Agent string that indicates a Netscape Navigator version of 4.x. These versions cannot handle compression of types other than text/html. The versions 4.06, 4.07 and 4.08 also have problems with decompressing html files. Thus, we completely turn off the deflate filter for them. The third BrowserMatch directive fixes the guessed identity of the user agent, because the Microsoft Internet Explorer identifies itself also as "Mozilla/4" but is actually able to handle requested compression. Therefore we match against the additional string "MSIE" (\b means "word boundary") in the User-Agent Header and turn off the restrictions defined before. Note! The DEFLATE filter is always inserted after RESOURCE filters like PHP or SSI. It never touches internal subrequests. Note! There is a environment variable force-gzip, set via SetEnv, which will ignore the accept-encoding setting of your browser and will send compressed output. Output Decompression mod_deflate module also provides a filter for inflating/uncompressing a gzip compressed response body. In order to activate this feature you have to insert the INFLATE filter into the output filter chain using SetOutputFilter or AddOutputFilter:
This code will uncompress gzip'ed output from example.com, so other filters can do further processing with it. Input Decompression mod_deflate module also provides a filter for decompressing a gzip compressed request body. In order to activate this feature you have to insert the DEFLATE filter into the input filter chain using SetOutputFilter or AddOutputFilter:
Now if a request contains a Content-Encoding: gzip header, the body will be automatically decompressed. Few browsers have the ability to gzip request bodies. However, some special applications do support request compression, for instance some WebDAV clients. Dealing with proxy serversmod_deflate module sends a If you use some special exclusions dependent on, for example, the User-Agent header, you must manually configure an addition to the
If your decision about compression depends on other information than request headers (e.g. HTTP version), you have to set the Vary header to the value *. This prevents compliant proxies from caching entirely:
mod_deflate directivesDeflateCompressionLevel
DeflateCompressionLevel directive sets the level of compression to be applied to the content. Higher value means better compression. Compression level value must be between 1 (minimum compression) and 9 (maximum compression). Example:
|