Compress your pages in Gzip and test results

December 2016




Intro


One of the main qualities of a website is fast loading. But it depends on the size of Web pages and their components. There are a number of techniques to reduce the overall size downloaded by the user.

Compressing web pages on the fly


The HTTP protocol provides a mechanism to compress web pages on the fly for the Mariners. To implement this compression, it usually takes to install a module on the server and configure it. Under the browser Apache, the module is the most used mod_gzip. Here is a sample configuration for this module:

<IfModule mod_gzip.c> 
   mod_gzip_on Yes 
   mod_gzip_can_negotiate Yes 
   mod_gzip_static_suffix .gz 
   AddEncoding gzip .gz 
   mod_gzip_update_static No 
   mod_gzip_command_version '/mod_gzip_status' 
   mod_gzip_temp_dir /tmp 
   mod_gzip_keep_workfiles No 
   mod_gzip_minimum_file_size 500 
   mod_gzip_maximum_file_size 500000 
   mod_gzip_maximum_inmem_size 60000 
   mod_gzip_min_http 1000 
   mod_gzip_handle_methods GET POST 
   mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]" 
   mod_gzip_item_include file \.html$ 
   mod_gzip_item_include file \.htm$ 
   mod_gzip_item_include file \.php3$ 
   mod_gzip_item_include file \.php$ 
   mod_gzip_item_include file \.js$ 
   mod_gzip_item_include file \.css$ 
   mod_gzip_item_include mime ^text/ 
   mod_gzip_item_exclude mime ^httpd/unix-directory 
   mod_gzip_item_exclude mime ^image/ 
   mod_gzip_dechunk Yes 
   mod_gzip_add_header_count Yes 
   mod_gzip_send_vary Yes 
</IfModule> 
  • Note that: It is also necessary to add mod_gzip to the list of modules installed by inserting the following line last in the list, because the Gzip compression should intervene at the end of the process:


LoadModule gzip_module /usr/lib/apache/1.3/mod_gzip.so
  • Then we must reload the Apache configuration for example by running one of the following:


apachectl graceful 
killall -HUP apache 
/etc/init.d/apache reload > /dev/null

Test the Gzip compression


Once the new Apache configuration taken into account, you can not easily check if compression is taken into account, since the web browsers (Firefox, IE, Opera, etc..) Handle the completely transparent.

Thus, it is necessary to look at the HTTP headers exchanged between the server and browser. For this there are online tools ready for use:

Related :

This document entitled « Compress your pages in Gzip and test results » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.