Increase page loading speed by using Gzip

Posted by Mohammed Mahgoub on Mon, May 12 2014 20:21:27

I've recently came across a very interesting article by Patrick Sexton on how to enable compression of HTML and CSS using Gzip.

Normally pages sent from a web server to your browser in text/html; content type format (without compression) but you can enable it by adding couple of lines to your .htaccess file this would increase page loading speed by 70% to 50%.

Patrick suggests two methods for Apache web servers using .htaccess mod_gzip and mod_deflate, some shared hosting providers like mine do not enable you to use Gzip so most likely mod_deflate would work for you.

 

Method 1:

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

 

Method 2:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

 

For CakePHP

As a CakePHP application has three .htaccess files you need to add the above code to the one found in app/webroot directory.

0 Comments

Add new comment