Support / KnowledgeBase

 
Search the KnowledgeBase Search

Compressing web pages with mod_deflate

  • Applies to: (dv) 3.5

  • Difficulty: Medium

  • Time needed: 10 minutes

  • Tools needed: ssh vi root

 

mod_deflate allows the Apache2 web service to compress files and deliver them to clients (browsers) that can handle them. With mod_deflate you can compress HTML, text or XML files by up to 70% of their original sizes, thus saving you server traffic, and speeding up page loads.


STOP:

  • If you currently do not have your root user enabled please visit the Root Access & Developer Tools section of your AccountCenter.

  • An understanding of vi is required for this article.  Please consult this article for further assistance.


NOTE:

  • Compressing files will increase load on your server,  but it is a small tradeoff considering your client's connection times will decrease significantly.

  • This will not exclude users with older browsers that cannot handle compressed content. The browser negotiates with the server before any file is transferred, and if the browser does not have the capability to handle compressed content, the server delivers the files uncompressed.

  • mod_deflate has replaced Apache 1.3's mod_gzip in Apache2.

  • This article shows how to enable mod_deflate globally across all the domains on your (dv) server.  Should you only wish to enable for a single domain you’d need to add the AddOutputFilterByType and BrowserMatch rules below to the VirtualHost section in your configuration. 

Steps

  1. Make sure that mod_deflate is enabled on your server.  Your (dv) server should have it enabled by default.  If the following command returns a line with a "#" at the beginning you will have to remove(uncomment) the "#" character using vi or the perl command below:
     grep 'mod_deflate' /etc/httpd/conf/httpd.conf
    
    If the result was LoadModule deflate_module modules/mod_deflate.so you can continue.  If the result was #LoadModule deflate_module modules/mod_deflate.so please run the following command:
     perl -pi -e 's/# LoadModule mod_deflate/LoadModule mod_deflate/g' /etc/httpd/conf/httpd.conf
    
    
  2. Now that we have verified that mod_deflate is in fact being loaded by Apache we must configure the module:

    First backup your existing conf file in case you need to revert back:
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak 
  3. Using vi we will edit our Apache conf file and add the following lines at the very bottom of the file, making sure they are separated from any other configurations:
    vi /etc/httpd/conf/httpd.conf 
    #
    # Deflate output configuration
    #
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  4. Save your file.  Now we need to check that Apache likes our changes using the apachectl command:
     /usr/sbin/apachectl -t
    
  5. You should see a Syntax OK message.  If not please check your file to make sure you modified the file correctly.  Next we need to restart apache using the same apachectl command:
     /usr/sbin/apachectl graceful

You have now enabled mod_deflate on your (dv) server!  You can see whether the changes are in effect using the following tool at http://whatsmyip.org/mod_gzip_test/


Here is a quick before and after for a default Plesk index page for a domain.  You can clearly see how this can benefit sites with rich content.

BEFORE:

1567_1

 

AFTER:

1567_2

 



Notes/Supplemental Resources:


Revisions:


2008-11-20:  Article Creation

User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue