Sunday, January 11, 2009 & IIS Tricks:- Using GZip Compression with IIS 6.0 to compress your dynamic content such as your aspx pages and increase the client side experience by downloading the pages fast.


In this article i will discuss how to enable gzip compression for the dynamic content.After following these steps you can enable compression for your aspx pages and other dynamic content.

But you have to be careful while compressing the dynamic content.I would suggest you to use the dynamic compression only when although you are using but most of your webpages are more likely to be static with only few of them changing now and then.

This is due to the  reason that compression brings in overhead on the server CPU and memory.So if the content is so much dynamic that it keeps on changing with every request its not at all advisable to use the compression for your dynamic pages.

Instead you can use gzip compression for your static pages such as html,css and js files.

But if your dynamic content is also near about static then you can use gzip compression provided as a built in feature of windows and IIS 6,by default it is not enabled here in this article we will go through the steps to enable the gzip compression scheme.

Enabling this compression can also be useful for developers who are running and testing their websites projects on their dev machines and are frustrated of long loading time of the content of their test websites and web applications.

Case Study

Here the case study consists of one of my recent projects which was a public facing website build up on Telerik's Sitefinity Content Management System.

So here in my case as the client was using Sitefinity so my pages were all .aspx pages but they were rather static as we CMS enabled their existing HTML content which was almost static.

So i will provide you with the reduction in size without any significant load on the server which was achieved using the gzip compression scheme with IIS

Lets analyze the page HTML,CSS,JS before enabling the compression.Below are the images which are self explanatory.


So it is now quite obvious that there is a lot of reduction in the actual page size which will be transferred across the wires.

So in specific situations you should enable compression for all the content and in most of the cases at least you should enable the gzip compression for the static content.

Enabling the GZip Compression

Now let us walkthrough the steps to enable gzip compression within the IIS.

  • To enable gzip compression first open the IIS Manager using "inetmgr"  command at your run command prompt.
  • After opening the IIS Manager navigate to the website properties by right clicking the website node.(Remeber here  all images are shown from Windows Server 2003)
  • Now go to the service tab and inside the http compression section enable compress application files and compress static files both and then click ok.



    After this just navigate to the Web Service Extension section and in this section add a new extension for gzip compression.Just Click Add new Web Service Extension and name the extension as Http Compressor or anything and in the Add section select the file gzip.dll which is inside C:\Windows\System32\Inetsrv\gzip.dll and then click OK.


   After adding the web service extension now we have to modify the IIS Metabase.xml file to achieve compression for dynamic pages    such  as aspx pages.

    IIS Metabase.xml file can be found in the directory C:\Windows\System32\Inetsrv\Metabase.xml

    Make sure to have another copy of this file as it is very important and if anything goes wrong here IIS will crash on your system.So make a backup of this file somewhere in your disk.      

    Now open this file in a simple editor either Notepad or Notepad++ and search for the entry called ICompressionScheme.There may be 6 occurrences of this word so one of them is for 'deflate" another one for "gzip" and the last one "Parameters" So choose the section having gzip as given below and add the required extension in the "HcScriptFileExtensions" as shown below we have added aspx. 

    Now save this file if your editor says that this file is opened in some other application or some other application is using your file then either stop the IIS service and the word wide web publishing service and then again try it, another method is to edit the metabase.xml file while it is being opened and used by the other applications.

    So for the second scenario we have to make some changes in the IIS properties which are given below

    After enabling the direct metabase edit you can now modify the metabase.xml file without stopping the IIS.After you are done you just have to restart the IIS using "iisreset /noforce"

    Now look for the changes now you should receive compressed content from the server.

    For checking you can use various online websites and tools such as pipeboost.

    Also there is a list of websites which can do this in one of my posts


User gzip compression over the default deflate compression every time for your all static pages and content leaving some special cases and scenarios.

And also try for compression of your dynamic content if it is more of a static type.

Getting file reduction upto 70-95% is a lot when we are talking about transferring data on net.


Happy Programming!!!!....

Stay tuned for more on upcoming posts..........


Anonymous said...

what about IIS7?

Anonymous said...

How Can I do this when I'm hosting my site with a web hosting company, and I dont have the control of the IIS ?

Anonymous said...

Interesting, this might come in useful. But, to play devil's advocate, did you notice that the loading times were all longer for the compressed pages above?

Giammin said...

what about overhead for zipping files?

maybe timespan gain compressing response could be almost equal to time spent for zipping(server) an unzipping (client) files.

Ashish Kumar said...

"Interesting, this might come in useful. But, to play devil's advocate, did you notice that the loading times were all longer for the compressed pages above?"

Yes you are correct in saying that,but the thing is that these images are for the first time load after compression been applied so they are taking time while getting compressed on the server.For the next call the time figures will also reduce as the IIS will server the already compressed content in case of static pages and also if dynamic pages have not changed then the same reason applies to the dynamic pages also.
Also i have already mentioned that when it is advisable to use the dynamic compression and when it is not advisable to implement this dynamic compression scheme.

"maybe timespan gain compressing response could be almost equal to time spent for zipping(server) an unzipping (client) files"
This can be the case in some situations but not in all so its at your own sweet will,test and match the requirement of your application then implement it.

Anonymous said...

I have used this in one of my projects earlier.
There are a few things to note before making a decision on using this technique.

1) Compression works fine for dynamic pages only when the content is not frequently changing.

2) The first call takes more time to fetch all the pages and compress. Subsequent requests can serve from the cache and will be faster.

3) This is efficient only for pages with lot of content and/or images. (Big page size). If used for smaller pages, the overhead in compression/decompression of the files will over shadow the quick download times.

Hope this helps.

Anonymous said...

Trackback from dotnetjunkies

What Ashish has forgotten to mention is that the two Matabase Properties (HcOnDemandCompLevel and HcDynamicCompressionLevel) can be tweakd to set the level of compression you desire. Higher compression levels generally result in small compressed files but with higher CPU and memory usage. So, one has a beefy server then by all means bump these values up, else you can experiment a little bit to get the optimum balance.

The Valid compression levels for both properties range from 1 to 10. (10 being max compression and 1 being lowest)

HcOnDemandCompLevel Metabase Property (IIS 6.0)

HcDynamicCompressionLevel Metabase Property (IIS 6.0)

Also, that these compression settings apply at IIS level and will be applied to all the websites hosted under it.

Hope this helps.

Andy said...

gZip is something we looked into but shied away from as IE6 isn't fully gZip compliant. What do you do about the large % of unfortunate IE6 clients?

Otherwise, great article :)

Anonymous said...

Nice article. You could have added the browsers compatibility list for gzip too..

Anonymous said...

Can it compress swf files. I have a flash site and i wants to know , if this can compress .flv and .swf files.

Anonymous said...

Hi I found few good tutorails on this blog.

you can see them if you like


Gabe Sumner said...

Very helpful article! Thanks so much for taking the time to write this.

Anonymous said...

i like ur website. thanks for this comment posting...

Anonymous said...

My website is rewrited without using file extensions like:

Internally pages are .aspx, but gzip compression doesn't work.

It works if pages are accessed directly:

Do you know how can I configure IIS?


Venkat said...


This is artical is very nice and very helpfull to me.

after I set this I found an error
"Permission denied for to call method Location.toString on"

If you any idean about this please advice.


Jason Prothero said...

Thanks for the article. Worked great for me although I had the same issue above where I'm using extension-less URLs and couldn't get the dynamic part to work. However, it really helped with my CSS and JS files.

As for the IE6 issue, this article may give you some leads on a solution:

James B Helms said...

how do you do this for something that doesn't have an extension, like JSON calls?

Boxing Equipment said...

Thank you so much!

I managed to follow this tutorial with some tweaking using Fasthosts dedicated Windows server we have.

Our sites are on classic ASP, mySQL odbc and some .NET and PHP applications. I really want to thank you for this as my site is now compressed according to Google Pagespeed for SEO and a few other sites including Pipeboost report.

Is a good article but the article has broken to links to IIS6 and IIS7. Although I enabled it, Microsoft do not go into your details.

Thanks so much! I currently get 55/100 under "Enable Compression" under the speed tool!

Anonymous said...


To those who do not have access to their IIS configuration panel (like using Windows Shared Hosting at GoDaddy), you can enable GZIP compression using web.config.

Check out my blog post below on how to do so.


asp net programmer said...

That was really informative post. I am learning programming and i found this post very helpful.

Post a Comment