GZIP is a compression method that can be used to significantly reduce the size of web pages as well as XML, CSS and Javascript files. The end-user must be using a browser that supports GZIP compression (most everyone in the world currently is).

Apache GZIP Compression

Using Apache and HTACCESS is the best way to compress your website pages. You can use mod_deflate or mod_gzip to compress your web pages. Deflate is a newer technology and may not be available on all servers.

It’s not only important to Gzip your web page, but also your JavaScript and CSS. That’s why using Apache is the prefered method as opposed to PHP.

Example of HTACCESS GZIP Compression

Add the following code to your .htaccess file in your main website directory. If you do not have an .htaccess file then you can create one. Not all web hosting providers allow their clients to utilize .htaccess, especially on shared hosting servers, but you may be able to contact your hosting provider and ask them to enable this functionality for you. A common location of .htaccess file is /home/accountname/public_html/.htaccess

###################################
# GZIP Setting #
###################################
#This will use the mod_deflate #
#Apache Module to compress your #
#Website pages including HTML, XML#
#CSS, and Javascript #
###################################

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

PHP GZIP Compression

PHP can be used to compress your PHP website pages. PHP is not as fast as using Apache and you don’t have the ability to GZIP javascript or CSS files, unless you run them through a PHP script first.

Example of PHP GZip

Example of PHP GZip for Javascript and CSS

And then instead of linking to your CSS file in your HTML files, link to the gzipcss.php file.

Expected Page Speed Increase

Not only will compressing your webpages, CSS and Javascript make your website load significantly faster, it is considered a High Priority Page Speed Rule by Google. I’ve seen it increase Google Page Speed rankings as much as 35 points.

Testing

If you aren’t sure if your website currently has a GZIP compression installed you can test it very simply with an HTTP Compression Test. You can test to see if your javascript and CSS are being GZIP’ed using RedBot

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Close
loading...