HTML and CSS Reference
In-Depth Information
compression method currently available and generally reduces the response size by
about 70%. DEFLATE is a patent-free compression algorithm for lossless data com‐
pression. There are numerous open source implementations of the algorithm. Apache's
mod_deflate module is one implementation that many developers are familiar with.
To learn more about the differences between GZIP and DEFLATE
compression, see Billy Hoffman's excellent article at http://zoompf.com/
2012/02/lose-the-wait-http-compression .
Approximately 90% of today's Internet traffic travels through browsers that claim to
support GZIP. All browsers supporting DEFLATE also support GZIP, but all browsers
that support GZIP do not support DEFLATE. Some browsers, such as Android, don't
include DEFLATE in their Accept-Encoding request header. Because you are going to
have to configure your web server to use GZIP anyway, you might as well avoid the
whole mess with Content-Encoding: deflate .
The Apache module that handles all HTTP compression is mod_deflate . Despite its
name, mod_deflate doesn't support DEFLATE at all. It's impossible to get a stock version
of Apache 2 to send either raw DEFLATE or zlib -wrapped DEFLATE. Nginx , like
Apache, does not support DEFLATE at all and sends only GZIP-compressed responses.
Sending an Accept-Encoding: deflate request header will result in an uncompressed
response.
If you use Apache, the module configuring GZIP depends on your version: Apache 1.3
uses mod_gzip , while Apache 2.x uses mod_deflate . Again, despite the naming con‐
vention, both use GZIP under the hood.
The following is a simple example of how to match certain file types to include in HTTP
compression. You would place it in the .htaccess file in Apache 2.4:
AddOutputFilterByType DEFLATE text/html text/plain
text/xml
Here's a more complex example that deals with browser inconsistencies can be set as
follows to compress everything except images:
<Location
/>
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
Search WWH ::




Custom Search