Advertuse

Search This Blog

Your Ad Here

Friday 1 July, 2011

How to compress our websites..!!??

Hi friends,
when you have website which has heavy  pages( means all page are loaded with lots of html and css etc...) .It is recommended to compress your website pages while serving. This will decrease your network traffic at your server. To achieve such compression of your website pages while delivering to browser  is done by two way.
 1) By server  setting
 2) do custom coding  in your web application


1) By server  setting
On IIS 6.0 and IIS 7.0 you can  have configuration option to set compression with variety of combination and permutation. following image depicts compression setting  in IIS 7.0.


then you click on  compression button. It will open new window  with all various option to do compression .


In IIS 7 compression automatically stopped when the CPU on the server is above a set threshold.  That means when CPU is freely available, compression will be applied,
 but when CPU isn't available, it may be temporarily disabled.
more over if  browser is older one or not supporting compressed pages then  also compression will not applied.

2) do custom coding  in your web application
now I will achieve  compression by plumbing our own code in http request-response pipeline of IIS server.

hence to do compression  in http request-response  pipeline I  have developed one  httpmodule which will applied on PostReleaseRequestState event of http request-response pipeline.
that httpmodule is develop as   dll which has compression class  inherit from IHttpModule. In that class I will do my core compression work at PostReleaseRequestState. moreover microsft ajax lib( update panel and all....) and compile resource file (.axd) do have their  own compression so i have handled them in little different way.


then this module   i have  plumbed in my application request -response pipeline  by  applying this module type in web.config as shown in below


you can download my sample code from my skydrive.  which linked below.
download

last thing
  this compression will not always good. because it will increase overhead on server  which might affect your server performance. And if your target audience have older browser mean( those  browser which does not support  compression) then it will not help you at all. so we  one need to  use this very carefully.
I have also found one  opensource project http://code.google.com/p/httpcompress/ which is fare better then my code. so you may try this also.

finally to test your site compression there are many online  tools are available. one can do googling to search out that.
and  i have test my own blog  on my fav  online tool  http://www.port80software.com/
and  below result i found


 as my blog is hosted by google so i have not use my code there.  but one can use  my code in their website and can check compression on such online tool .





2 comments:

Dip said...

Divyang Is it possible to do this compression in LAMP?

divyang4481 said...

yes in apache server there are some configuration using that you can do that.
you can refer this code for php
http://www.webcodingtech.com/php/gzip-compression.php