Knowledgebase: Shared Web Hosting
Page load time optimization (GZIP and DEFLATE)
Posted by Helpdesk Admin on 04 June 2014 01:44 PM

When optimizing the load time of your web pages, the number and size of files to be transferred is important especially for visitors on slower broadband connections.

It is well known that image files should be optimized before uploading to the web server in order to ensure the page loads as fast as possible.

However, other static content such as the page HTML code, Style Sheets (CSS files), Javascript (.js files) etc. all form an increasing proportion of the data to be transferred especially for dynamic websites that use interactive features such as Ajax, pop-up menus etc.

Such data consists largely of plain text and so is very suitable for compression - it is not unusual to be able to reduce such content by 80 or 90% leading to an improvement in page loading time.

In general, there are two methods used for compressing such data.

For "pure" compressible static content (.js, .css, .html files) you can use Apache's mod_deflate module to do this. The module is already present on all Linux hosting accounts, however you need to enable it via a .htaccess file in the main root directory of the website.

For full information on mod_deflate, please view the information at http://httpd.apache.org/docs/2.2/mod/mod_deflate.html

The following directives placed in the .htaccess file work well for many situations:

Header append Vary User-Agent env=!dont-vary
AddOutputFilterByType DEFLATE text/css text/javascript text/plain text/html text/richtext text/xml
AddOutputFilter DEFLATE js css htm html xml

*** You should not use mod_deflate to compress image files (.gif, .jpg, .png, .pdf etc) as these are *already* compressed. Running mod_deflate on such content will actually slow delivery because of the additional computational overhead. ***

If your site is using PHP (most do including WordPress, Joomla, Drupal sites etc) then you can enable GZIP compression for the PHP output. This is done by enabling gzip libraries for PHP.

The following directives should be placed in a file named ".user.ini" in the root directory of the site:

zlib.output_compression = On
zlib.output_compression_level = 5

Please note that it may take a period of time for the above change to take effect because of caching.

(5 vote(s))
This article was helpful
This article was not helpful