Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Feb 042010

Turn on content compression in Apache


By turning on content compression in Apache, content's transfer size can be reduced for users and hence a faster loading time. However, not all content types can be compressed, e.g. images, videos, we usually only compress text content types, e.g. html, xml, css & js.


Add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/xml application/xml application/javascript application/json text/css text/plain
    header set Vary Accept-Encoding

    # Don't compress images - Important for IE caching bug
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    header unset Vary env=dont-vary


Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_deflate is enabled

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>