How can i (gzip) http responses (using Apache)?

Apache allows you to gzip responses provided the calling application (IE, or any other) is capable of handling zipped responses. The calling application sends information about its capability to handle zipped responses in accept-encoding http request header.

Following configuration is necessary in Apache for this.:

Create a deflate.conf file with following contents in <Apache_Home>/conf/extra

—deflate.conf file—-

<Location />
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/jpg
AddOutputFilterByType DEFLATE image/gif
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE application/x-shockwave-flash
AddOutputFilterByType DEFLATE application/x-amf
AddOutputFilterByType DEFLATE text/javascript
</Location>

DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat ‘”%r” %{output_info}n/%{input_info}n (%{ratio_info}n%%)’ deflate
CustomLog /usr/local/Apache-2.2.8/logs/deflate_log deflate

———–end of file ——-

In the above file comment out any response type you are not interested in zipping. So if you do not want images to be compressed, comment out the following lines as shown below:

#AddOutputFilterByType DEFLATE image/png
#AddOutputFilterByType DEFLATE image/jpg
#AddOutputFilterByType DEFLATE image/gif

In <Apache_Home>/conf/httpd.conf file:

Make sure following entry exists:

LoadModule deflate_module modules/mod_deflate.so

#Moddeflate Options file
Include conf/extra/deflate.conf

Thats all you are done. You can see the deflate log: /usr/local/Apache-2.2.8/logs/deflate_log deflate.

Tested in: Apache 2.2.8/Linux

Enjoy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: