Click here to Skip to main content
15,881,882 members
Articles / Web Development / IIS

How to enable HTTPCompression in IIS6

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
17 Oct 2010CPOL4 min read 31K   11   1
Enabling HTTPCompression in IIS6

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

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. So IIS provides a feature to compress the responses and most common browsers support the HTTP Compression.

This 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 algorithms supported. One is gzip and the 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 is very small by default less than 60 to 70k. Then I think you don't need this. Moreover, if your users are having very high speed Internet, then also you can ignore it because obviously the compression/decompression is an overhead if you are not gaining much.

4: How HTTPCompression works.

When a browser sends a request to IIS, it also sends the information about what kinds of encoding it 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 the 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 finds 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 the 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 in gzipped format.

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

Actually, when the 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 in normal format.

So you don't need to worry about if 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.

  1. Static (for static files like some CSS, JavaScript file, etc.)
  2. Dynamic (means for dynamic generated page/response)

There is no console available to configure HTTPCompression.

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

  1. First: Update the IIS metabase files directly.
  2. 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.

  1. First: Configure the IIS for HTTPCompression
  2. 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 your web server is ready to compress the responses based on incoming requests.

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

Note: I have explained above the settings for IIS6.

Please share your feedback.

Thanks,
Brij


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.

He is a very passionate .NET developer and have expertise over Web technologies like ASP.NET 2.0/3.5/4.0, jQuery, JSON, Javascript, IIS and related technologies. He is also a Exchange Server (EWS) Specialist. He has great experience in design patterns and N-Tier Architecture.

He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.

He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.

Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.


Visit his Blog: Code Wala

Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008

Comments and Discussions

 
QuestionIIS Compression Pin
Murugan819-Oct-13 3:36
Murugan819-Oct-13 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.