How to activate gzip compression for better client performance (mod_deflate)

gzip-vi-banner

Using gzip, the Apache webserver module mod_deflate / mod_gzip allows HTML and CSS files to be compressed, reducing the size of transferred files by up to 70%. This results in shorter loading times for your website.
Especially for visitors accessing your website with relatively slow connections (using their smartphones for example), the compression can lead to a noticeably better client performance.

Activating gzip / mod_deflate compression

You can activate gzip compression by adding an entry to the .htaccess file on your webspace.

  1. Access your webspace via SFTP and open the .htaccess file with a text editor (such as Notepad++).
  2. Paste the following code at the end of the .htcaccess file.
    Activates compression only for specific MIME types (learn more about MIME types):

    <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    </IfModule>
  3. Save the .htcaccess file and upload it to your webspace:
    The edits to the .htcaccess file apply to the storage directory and its subdirectories respectively.

Testing gzip / mod_deflate compression

You can test the gzip / mod_deflate compression with Google PageSpeed Insights for example. You can also use the developer tools of your browser (Chrome or Firefox for example) to display the content-encoding information for your website.
Open your website with the browser of your choice, activate developer tools and switch to the Header tab. Look for Content-Encoding: gzip.

Please note: A small number of webhosting packages might need additional adjustments to enable gzip. If you need help enabling gzip, please contact our support team.

You might also be interested in

Activate 1&1 CDN for a Domain (1&1 Help Center)

 

Please rate this post :

17 thoughts on “How to activate gzip compression for better client performance (mod_deflate)

  1. Daris says:

    Hi, QQ(I hope). I tried using the above tip for shared hosting:

    php_flag zlib.output_compression on
    php_flag zlib.output_compression_level 5

    However when I add that to my .htaccess file I get a server 500 error. I’m using php 5.6… Anything else I can try?

    1. Philipp Bellmann says:

      Hey Daris,
      we are currently working on a solution and I will update here as soon as possible. My apologies.
      Phil

      1. Daris says:

        Hi… Any updates on this? I’m Really looking forward to being to able to use gzip / compression on shared sites.

        1. Gg says:

          Hi, I saw your suggestion and I had the same problem so I saw a line added in .htaccess: AddHandler x-mapp-php5.5 .php .html .htm .js – well it worked out but I had in php.ini: zlib.output_compression = On and zlib.output_compression_level = 9 and allow_url_fopen = On . Well the AddHandler is a must and the others I think too, try and tell us

  2. BKToh says:

    Hi,

    I copied and pasted the code to the .htaccess file, did a test and the result says Gzip is not enabled. Please help.

    BK

  3. Ed Kiefer says:

    I did the same. Copied and pasted the code into my .htaccess file and sames results. Gzip is not enabled. Why?

  4. Mike Saeger says:

    I just talked to Technical Support on the phone about this. In their shared hosting environment, the .htaccess file cannot turn on compression. She said she is sending me information on ZLID which can enable compression via PHP. I’m waiting for the information.

  5. Mike Saeger says:

    Make that ZLIB compression. Here is the link she sent me:
    http://php.net/manual/en/book.zlib.php

  6. Mike Saeger says:

    So after reading the info on ZLIB, all you have to do it add the following to the top of your PHP application:

    Everyone one of my PHP programs now show that they are Gzipped.

  7. Mike Saeger says:

    <?php
    ob_start(“ob_gzhandler”);
    ?>

  8. Thanks Mike for this information!
    But I did not understand where to add this code 🙁

    Can you give us more details on how to do it (which *.php, etc …)?

    Thanks a lot by advance!

  9. jon says:

    So this post is completely useless because 1and1 does NOT run mod_deflate.c on Apache. Kind of senseless as PHP compression stands to use more CPU and not enabling mod_deflate.c increases bandwidth usage.

    I guess we will never know what engineer thought this to be smart.

    1. 1and1help says:

      Hi jon,

      quoting the article:

      “Please note: A small number of webhosting packages might need additional adjustments to enable gzip [mod_deflate]. If you need help enabling gzip, please contact our support team.”

      Please send us an e-mail to help@1and1.com with your customer id, referring to this article. Then we will do the additional adjustments for you on our server and you can use mod_deflate in the future. 🙂

      Thanks and best,
      Michael, 1&1

      1. Mr Mistry says:

        Michael,

        I’ve emailed 1&1 on the address you gave above including all the information you had asked for and I haven’t heard anything? Also I opted to call 1&1 support and they said they do not support GZip and they didn’t know what mod_deflate was!

        What can I do?

        Regards,

        Mr Mistry

        1. 1and1help says:

          Hi Mr Mistry,

          we received your e-mail and will reach out to you asap.

          Thanks and kind regards,
          Michael, 1&1

  10. Interested to find out what the answer to Mr Misty was above. Can someone share it here?
    thanks

    1. 1and1help says:

      Hi Sam,

      I think we sorted this out with our customer. 🙂 May I ask you where your question is coming from? As I can see by the domain name you added to your comment, mod_deflate is already supported on the webserver your account is located at.

      Best regards,
      Michael, 1&1

Leave a Reply

Your email address will not be published. Required fields are marked *