How to enable HTTPCompression at IIS6

Last week, I was working on performance improvement of one of my projects. So I read several Articles on Internet and found that we can configure HTTPCompression on IIS. It compress the response sent to the browser and the size of the response get reduced dramatically i e major improvement in performance. So I wanted to share you all.

I’ll discuss it point wise.

1: Why do we need HTTP compression?

Nowadays, we are building Rich Internet Applications, which is increasing the size of  Pages heavily. Means the more page size, more time it’ll take to load. But, IIS provides a feature to compress the responses and most common browsers support the HTTP Compression.

Means you can configure, HTTP compression at your web server, and browsers will understand it.

2: How much page size will be reduced.

Normally there are two algorithm supported. One is gzip and other one is deflate. I used Gzip in my website and found that the Page size was reduced by 60 to 70%.

3: When we don’t need compression.

If your page size are very less by default less than 60 to 70k. Then I think you don’t need this. Also if your users are having very high speed Internet then also you can ignore it. Because obviously the compression/decompression is a overhead if you are not gaining much.

4: How HTTPCompression works:

When a browser send a request to IIS, it also the send the information that what all kind of encoding supports. You can see the request header by many tools (One is Firebug that is available as a plugin for Firefox). You will be able to see following line in the request header.

Accept-Encoding: gzip,deflate

It says that this browser accepts gzip and deflate encoding

Now when IIS receives the request and find that that the requester can understand the given encoding. Based on the configuration, it encodes the response.

Now you can see the Response header. There it is mentioned, in what encoding is done on response as you can see it in header as

Content-Encoding: gzip

It means the response was encoded with gzip.

Here I am showing you all an example of Gmail.

Here I am showing the request header sent by the Firefox 3.5

It says it can accept encoding : gzip,deflate

Now let’s see the  response header

As you can see, the response is sent is gzipped format

5: What will happen if Browser does not understand any encoding?

Actually when browser sends a request to the server it tells the server what all encoding it supports and that is available in Request Header. If it does not support,  it may not send the Accept-Encoding tag.

Now when IIS receives the request and if it does not find any encoding mechanism supported by Requester, It does not apply any compression/encoding mechanism and the response is not encoded and sent it in normal format.

So you don’t need to worry about, it any browser does not understand gzip or deflate, then what will happen. IIS takes care, IT only encodes when it is supported by the requester.

6: How to configure HTTPCompression at IIS,

There are two types of Compression that can be configured.

First one: Static ( for static files like some css, javascript file etc.)

Other one: Dynamic (means for for dynamic generated page/response) .

There is no console available to configure to Configure HTTPCompression.

So there are two ways to configure HTTP compression at IIS.

First: Update the IIS metabase files directly.

Second: Use some commands to update it.

Here I’ll discuss the second one and will discuss the commands that can be used to configure it.

Here you need to do two things.

First: Configure the IIS for HTTPCompression

Second: Configure what all types/extension will be encoded

So for that you need to run the following commands at your web server:

Configure the IIS6 for HTTP Compression-

First Open command prompt and go to your IIS root folder, normally it would be “c:\inetpub\adminscripts\” then follow the below steps.

Static Compression:

To see whether Compression is enabled or not:

cscript adsutil.vbs get w3svc/filters/compression/parameters/HcDoStaticCompression

Enable/Disable Static Compression

adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true/false

To view what all files will be encoded:

cscript adsutil.vbs get W3SVC/Filters/Compression/gzip/HcFileExtensions (for gzip)

cscript adsutil.vbs get W3SVC/Filters/Compression/deflate/HcFileExtensions (for deflate)

To add more files for Compression

cscript adsutil.vbs set W3SVC/Filters/Compression/gzip/HcFileExtensions “js” “css” “png” “bmp” “swf” “doc” “docx” (for gzip)

cscript adsutil.vbs set W3SVC/Filters/Compression/deflate/HcFileExtensions “js” “css” “png” “bmp” “swf” “doc” “docx” (for deflate)

Dynamic Compression:

To see whether Compression is enabled or not:

cscript adsutil.vbs get w3svc/filters/compression/parameters/HcDoDynamicCompression

Enable/Disable Dynamic  Compression

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true/false

To view what all files will be encoded:

cscript adsutil.vbs get W3SVC/Filters/Compression/gzip/HcScriptFileExtensions (for gzip)

cscript adsutil.vbs get W3SVC/Filters/Compression/deflate/HcScriptFileExtensions (for deflate)

To add more file extension

cscript adsutil.vbs set W3SVC/Filters/Compression/deflate/HcScriptFileExtensions “asp” “exe” “dll” “aspx” “asmx” (for gzip)

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions “asp” “exe” “dll” “aspx” “asmx” (for deflate)

Now reset the IIS. Now you web server is ready to compress the responses based on incoming Requests.

I’ll suggest to all configure it at IIS6 and see/analyze the performance.

Note: I have explained above the settings for IIS6.

Please share you feedback:




5 thoughts on “How to enable HTTPCompression at IIS6

  1. Hello Brij’s
    Your articles really helpful to me.
    Will u plz me help me. I am working on Reapeter. I create paging functionality for itand for that i create one web control library. So anyone when used it it provide paging functionality like gridview and the work for user is datasource binding.So now i want to provide Sorting functionality to it . i am trying but problem is repeater is in html format. so how i know cloumn.

    • There are several ways to do this.
      First : You can have a hidden field. When user clicks on any header column, you update the column name in hiddden field from Javascript and make postback and at server side you can get the hiddenfield value sort it accordingly.

      Another better way: Put link button in column of repeater.And on server click of linkbutton, you can implement Paging functionality.

      Hope it helps.

  2. Pingback: A way to improve performance of your Web Application significantly « Brij's arena of .NET

Leave a Reply

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

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

Facebook photo

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

Connecting to %s