Optimization: compressing content

To optimize the loading of a web page is necessary to reduce the maximum number of requests or size of the files transmitted. To help save transfer web servers implemented forms of compression, whereby the content is compressed before sending to the browser.

Today most browsers support two compression formats, it can be observed in the headers sent by the browser to make a request. In the Accept-Encoding property with two values:
gzip is a free compression format, developed by the GNU project, is the most popular because most browsers support it also offers savings of 66% on average.
deflate less effective than gzip, it offers a savings of 60% on average.

compressed files with gzip

It is advisable to only compress html, php, css, js and some other files in text files. In the case of jpg, png, gif, pdf files these are already compressed and apply gzip can increase the size of the files and even consume server CPU. Another rule to consider is recommended to compress files larger than 1Kb.

GZIP use with Apache 1.3

In the case of Apache 1.3 gzip compression is handled by the mod_gzip module. To do this you can use the mod_gzip_item_include statements to include files to compress and mod_gzip_item_exclude to exclude files. Then edit the .htaccess file and include the following code.

mod_gzip_on Yes
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.js$
mod_gzip_item_include mime ^application/javascript$
mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include handler ^application/x-httpd-php
mod_gzip_item_exclude mime ^image/.*

GZIP use with Apache 2.x

For versions of Apache 2.x compression is managed by the mod_deflate module (Do not confuse the module name with compression, for this generates gzip compression). To compress files we can use the AddOutputFilterByType sentence as follows:

AddOutputFilterByType DEFLATE text / html text / css application / x-javascript



Please enter your comment!
Please enter your name here