How do I use gzip on my website?


If you have large text files on your site that regularly take a long time to load, you can reduce the load time by compressing the contents through gzip.

This does not require you to compress the files themselves, but you do need to set up mod_deflate in Apache.

To set up mod_deflate:

  1. Create a new or open your existing .htaccess file
  2. Add the following line:

AddOutputFilter DEFLATE text/html text/css text/plain application/xml application/javascript application/json application/rss+xml application/atom+xml
Where the file types are the ones you want to be compressed

  1. Upload your revised .htaccess file

This works primarily with uncompressed text data.  With other files, the time that the server puts into compressing the file will be more than the time it takes to load the original size.

You can read more about mod_deflate on the Apache site: http://httpd.apache.org/docs/2.4/mod/mod_deflate.html

If your website is PHP-based, you can also include gzip compression in the PHP code itself.

You can use ob_gzhandler, which is part of the ob_start function.  For more information on ob_gzhandler, please read the documentation on the PHP site: http://php.net/manual/en/function.ob-gzhandler.php



Article ID: 433
Created On: Mon, Mar 16, 2015 at 3:52 PM
Last Updated On: Thu, Apr 23, 2015 at 12:18 PM

Online URL: https://www.heartinternet.uk/support/article/how-do-i-use-gzip-on-my-website.html