SpeedUp Webpages Using gzip compression

Posted on October 3, 2009. Filed under: General | Tags: , , |

It is one of the important point to attract web traffic and maintain the level of the website by its speed.Google is gold medalist in this.Dont want to know why ? .Yeah ! But not only due to there bursty servers but also very minute changes and proper arrangements of HTML and proper compression used while transfer of data from server to user.

Google uses a gzip compression for transfer of web pages.That means the data which is to be transferred is compressed by gzip compression and then sent to the user.The browser decompress the gzip data and show to the user as usual data.But if the browser dont support gzip ? Yeah , Google Verify before the gzip compression that the browser supports gzip compression or not else it will send data or html in normal way.

How much is the efficiency of this system ?

I have done some experiments on gzip compression.I made two php files one supporting gzip and other not.The duration of loading of php file without gzip compression was ~128 ms [It was hosted on local host] and when I clicked on php file with gzip compression , I was amazed to see the results it was about ~ 56 ms .So this really worth.

How is this technically possible ?

It is very easy with PHP , I will post the code which is to be pasted above the php file you want to compress.

<?php
ob_start(“ob_gzhandler”);
?>

This will speed up your loading speed of a web page.But this code is incomplete without validation that the browser supports gzip or not .

Browser sends the header to the server named “Accept-Encoding” , If the gzip is listed in that means you can use it else normal encoding will used which is by default.

<?php

if(preg_match(‘/gzip/’,$_SERVER['Accept-Encoding']))

{

ob_start(‘ob_gzhandler’);

}

?>

So this way you will able to add this system to your PHP pages , But what about others like asp , cgi etc.Using same logic you can add in other programming language also as the gzip and Accept-Encoding will be the common terms throughout the web .

Cheer

Advertisement

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

5 Responses to “SpeedUp Webpages Using gzip compression”

RSS Feed for TheChetan’s Blog Comments RSS Feed

I’ve added the compression to my php pages successfully but what about my javascript and css pages? how do i add it to them? i haven’t got access to the .htaccess file so i need to do it through the programming languages.

thanks

I think it will be ok with javascript files :) , else you can use dynamic javascript pages like js.php which will return javascript with javascript header

nice trick thanks for sharing.

You are welcomed

Excuss me :) You can check google cache for date of post and can I have a link to your post please ?


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.