How to Enable Gzip Compression

Originally posted on www.clook.net.

 

Optimising your website will not only provide a better visitor experience, it will also position you to rank well with Google, Bing, Yahoo and other search engines. One way to speed up websites is to enable gzip compression…

What is Gzip compression?

Gzip is a way of compressing files sent from your server to increase the speed to which they are transferred to the user’s web browser.

It can reduce page sizes by up to 70% and subsequently improve load times.

Different ways to activate Gzip compression

Depending on your Content Management System, and/or server type you will find there are various methods to enable Gzip compression…

WordPress and Gzip compression

Most popular caching plugins have the facility to enable the function via their settings. I use WP Fastest Cache and the option is available via the settings home page:

Gzip Compression

Enable compression via .htaccess

Typically when enabling Gzip via a WordPress plug-in it is done by adding content to your .htaccess file. If you do not use WordPress or prefer not to use a caching add-on, you can enable Gzip compression manually by adding the following to .htaccess:

<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>

Enabling compression on Apache webservers

If gzip fails using the instructions above, remove the code added to .htaccess and replace with:

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

How to 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;

Gzip compression on LiteSpeed Web Servers

You can enable compression on LiteSpeed servers via the configuration menu under ‘tuning’. Simply navigate to ‘enable compression’ and make sure it is turned on.

Checking Gzip is enabled

A good tool to analyse on site performance is GTmetrix.com. A previous blog post Improve Your GTmetrix Score in Under 30 Minutes gives insight on steps you can take to improve your score. Enter your website url, click ‘Analyse’ and once the report has run you will be notified whether Gzip has been enabled successfully:

Gzip Compression