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

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Do you support SSI (Server Side Includes)?

Yes we do. SSI (Server Side Includes) are tags that are placed in HTML pages, and evaluated on...

How can I change the file name extension of my index page?

It is possible to name your default index page something other than index.html, index.cgi,...

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 can I force a particular charset? (Character Encoding)

You are able to set a default value for the media type charset parameter (the name of a character...

How do I edit php.ini (PHP settings) for my hosting package?

Becuase of the way in which we run PHP, you are able to customise its behaviour with php.ini...