Divyang's ICollection

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.

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 .

3 comments for “How to compress our websites..!!??

  1. Dip
    July 1, 2011 at 4:44 am

    Divyang Is it possible to do this compression in LAMP?

  2. July 1, 2011 at 4:52 pm

    yes in apache server there are some configuration using that you can do that.
    you can refer this code for php

  3. sbo
    January 27, 2012 at 7:27 am

    CoPilot Live can help make a planned getaway even more enjoyable. With millions of Points of Interest including restaurants, parks to grill, and a variety of attractions, CoPilot Live can help you find and navigate to your ideal destinatisbobeton this weekend. Whether it’s a short drive to the beach or a long vacation getaway, GPS navigation on a mobile device is proving to be a very popular traveling companion

Leave a Reply

Your email address will not be published. Required fields are marked *