Knowledgebase Banner Advert

How do I enable gzip compression on my website

You can decrease load times on your website by compressing the contents.

You can do this on any website (home-made, WordPress, Joomla, etc.) with gzip using the Apache module mod_deflate.
To do this, you first need to create a file in your public_html directory called ".htaccess" or edit your existing .htaccess file.

The .htaccess file is a configuration file in which you can configure many things, of which compression is just one.

In this .htaccess file, you can specify types of file to be compressed with directives like this (just keep the lines for the file types you want to compress):

#Deflate
#Make Sure Resources Are Compressed In Transit
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can Not Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

 

The full documentation on using this mod_deflate can be found here:

http://httpd.apache.org/docs/2.4/mod/mod_deflate.html

Alternatively, in a PHP based website you can implement gzip compression directly in the code.

This is done using ob_gzhandler which is done as part of the ob_start function. The full documentation on this can be found here:

http://php.net/manual/en/function.ob-gzhandler.php

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

When I try and view my website I get an HTTP Error 403 - Forbidden message.

A '403 Forbidden' message means that the browser has requested a page that it is not...

My links are not working. What is wrong

First of all, check that the link is correctly spelled, and that the correct case is used -...

I have installed the formmail script but my form is not working

The Formmail Script is provided via the Control Panel, full usage instructions can be found after...

How can I enable directory indexing

If you want to see a list of files in a directory when viewing it in a browser rather than a web...

How do I install Locked Area Lite?

Before you install Locked Area Lite you need to create a folder that you want to...