How To Enable Gzip Compression

28th June 2017no responsesWeb Design

What Is Gzip Compression?

  • Gzip is a method of compressing files (making them smaller) for faster network transfers.
  • It is also a file format.Compression allows your web server to provide smaller file sizes which load faster for your website users.Enabling gzip compression is a standard practice.

If you are not using it for some reason, your webpages are likely slower than your competitors.

How To Enable Gzip Compression

  • Compression is enabled via webserver configuration
  • Different web servers have different instructions (explained below)

Here are the most common ways to enable compression including .htaccess, Apache, Nginx, and Litespeed webservers.

Enable Compression Via .htaccess

For most people reading this, compression is enabled by adding some code to a file called .htaccess on their web host/server. This means going to the file manager (or wherever you go to add or upload files) on your webhost.

The .htaccess file controls many important things for your site. If you are not familiar with the .htaccess file, please read my working with .htaccess article to get some know how before changing it.

The code below should be added to your .htaccess file…

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Save the .htaccess file and then refresh your webpage.

Check to see if your compression is working using the Gzip compression tool.

Enable Compression on Apache Webservers

The instructions and code above will work on Apache. If they are not working there is another way that may work for you. If the above code did not seem to work, remove it from your .htaccess file and try this one instead…

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

Enable Compression on NGINX Webservers

To enable compression in NGINX you will need to add the following code to your config file

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable “MSIE [1-6].(?!.*SV1)”;

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

Enable Compression On Litespeed Webservers

The ideal way to enable compression in Litespeed is to do it through the configuration under “tuning”. Just go down to “enable compression” and check to see if it is on, if not click “edit” then choose to turn it on. While you are there, look over the several Gzip options that are nearby.

How Effective Is GZIP Compression?

Compression of your HTML and CSS files with gzip typically saves around fifty to seventy percent of the file size. This means that it takes less time to load your pages, and less bandwidth is used over all.

How Compressed Files Work On The Web

When a request is made by a browser for a page from your site your webserver returns the smaller compressed file if the browser indicates that it understands the compression. All modern browsers understand and accept compressed files.

Testing Compression

To see if gzip compression is working use our gzip compression tool.

Also consider using the page speed tool which will test compression and many other factors.



Author: Peter Wootton

Top Ranking SEO Expert & Consultant - Ranked Top On Google For "SEO Manchester". Specialist in Technical SEO.


No Comments on How To Enable Gzip Compression

  1. Connor Gibson
    January 14, 2010Reply

    Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Sed posuere consectetur est at lobortis. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Vestibulum id ligula porta felis euismod semper.

  2. Nikolas Brooten
    February 21, 2010Reply

    Quisque tristique tincidunt metus non aliquam. Quisque ac risus sit amet quam sollicitudin vestibulum vitae malesuada libero. Mauris magna elit, suscipit non ornare et, blandit a tellus. Pellentesque dignissim ornare elit, quis mattis eros sodales ac.

    • Pearce Frye
      February 22, 2010Reply

      Cras mattis consectetur purus sit amet fermentum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Etiam porta sem malesuada magna mollis euismod. Maecenas sed diam eget risus varius blandit non.

      • Nikolas Brooten
        April 4, 2010Reply

        Nullam id dolor id nibh ultricies vehicula ut id. Cras mattis consectetur purus sit amet fermentum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

  3. Lou Bloxham
    May 03, 2010Reply

    Sed posuere consectetur est at lobortis. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.


Would you like to share your thoughts?

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