How To: HTTP Compression in IIS 6.0

How To: HTTP Compression in IIS 6.0
Source: The .NET Guy’s Web log

1. Allow the compression ISAPI to run

IIS 6's new security system prohibits ISAPI DLLs from running by default, so you need to tell IIS 6 that it's okay to let the compression ISAPI DLL run.

01. Open the IIS admin tool (inetmgr); drill into your server, and right-click on "Web Service Extensions".

02. Choose "Add a new web service extension". For the extension name, use whatever you want to identify it in the list (I used "HTTP Compression Extension").

03. You need to add a single required file, which is \Windows\System32\inetsrv\gzip.dll, the ISAPI responsible for doing gzip and deflate compression.

04. Check the "Set extension status to allowed", then click OK.

05. You should have a new web service extension in your list called "HTTP Compression" (or whatever you named it), and it should have a status of "Allowed".

2. Select compressible content

IIS 6's compression system only compresses a very limited set of content. You need to enable compression for the appropriate file extensions (specifically, .aspx files for your ASP.NET pages, and perhaps any static content you want compressed as well).

01.   You're going to edit the Metabase. To do this, you first need to shut down IIS.

02.   In the IIS admin tool, right click on your server name in the left panel, and choose All Tasks -> Restart IIS.

03.   On the restart dialog, choose "Stop internet services" and click OK. When IIS is shut down, you'll need to edit \Windows\System32\inetsrv\MetaBase.xml (make a backup first!).

04.   Search for "IIsCompressionScheme". There will be two XML elements, one for deflate and one for gzip. Both elements have properties called HcFileExtensions and HcScriptFileExtensions. These contain a space-delimited list of file extension for compressible content.

05.   At a bare minimum, you'll need to add “aspx”, “ascx” to the HcScriptFileExtensions list. Note that if the properties are left blank, then all content, regardless of file extension, will be compressed.

Note:

1.      Make sure that IIS process user account has required privileges on the compression temp folder.
2.     
Do never try to compress image types (jpg, gif, png, tiff etc…)

17 Comments

  • You sure you mean .ascx to be added to the compressible file list?

  • I cannot save the .XML-file even though I have enough NFTS-permissions (I thought full-control would be enough... silly me) I was wondering... WHY, IIS is stopped, so it should not be in use... file-security cannot be the problem... so it beats me... any suggestions?

  • My IIS6.0 HTTP 1.1 compression works pretty good. And my experience shows that:



    1. You don't have to do step 1, which manually installs gzip.dll ISAPI. In the metabase xml file you can see it's already been taken care of.



    2. You don't have to modify metabase xml file manually, just use adsutil in C:\Inetpub\AdminScripts\ directory. the following script will enable most common file extentions for gzip/deflate compression.





    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "ppt" "xls" "xml" "pdf" "xslt" "doc" "xsl" "htc" "js" "css"



    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "ppt" "xls" "xml" "pdf" "xslt" "doc" "xsl" "htc" "js" "css"



    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx" "ashx"



    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx"



    IISreset.exe /restart



  • I've followed this example to a tee, and I cannot get CFM files to compress. Anybody know what the trick is?



    Thanks.

  • Stefan,



    I had the same problem. I had to stop the you can save World Wide Web Publishing service and the IIS admin service. After that I could save the metabase.

  • Hi,

    I want to use HTTP compression for XML files being returned from the server. I just want to know whether XML files comes under static or Dynamic content.

    Please help me.

    Ravindra.

  • No matter what I try, all file types are being compressed when viewed by Fiddler. I have edited MetaBase.xml, and added spcific file types for HcFileExtensions, for static and dynamic pages, both in deflate and Gzip, but all file types including gif is being compressed. I know that when you enable Gzip in Tomcat for example, when you write compression="force", it does not matter what you write in compressableMimeType= it always compresses all types of files. Does IIS have something like this that I am Missing?

  • > No matter what I try, all file types are being compressed

    I had the same after I had manually edited the metabase.

    after running the 5 lines listed by charles (that use adsutil.vbs to changed these settings), it works fine. maybe I had mistyped? or maybe the seperator for the list of file extensions is senstived to extra whitespace?

  • A sensible dog would eat the thing. ,

  • Try this:

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/parameters/HcDoDynamicCompression true
    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html"

    "js" "css" "xml" "xlt" "txt" "ppt" "xls" "pdf" "xslt" "doc" "xsl" "htc"
    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html"

    "js" "css" "xml" "xlt" "txt" "ppt" "xls" "pdf" "xslt" "doc" "xsl" "htc"
    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "cfm"

    "cfc" "asp" "dll" "exe" "aspx" "asmx" "ashx" "ascx"
    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "cfm"

    "cfc" "asp" "dll" "exe" "aspx" "asmx" "ashx" "ascx"
    IISreset.exe /restart

  • Hi,

    Can you kindly explain why compressing a image is a bad thing as per your note " Do never try to compress image types (jpg, gif, png, tiff etc…)"?. If the image is around 46-60 KB is that still a big issue?.

    Have you got a decent article to support that or an example please?.

    Thanks.

    Regards,
    Rajesh.

  • It's great to be great , but it's greater to be human.

    -----------------------------------

  • -----------------------------------------------------------
    Hey quite good web site!

  • -----------------------------------------------------------
    I like to require breaks during the day and browse through some blogs to see what others are saying. This blog appeared in my searches and I could not help but clicking on it. I'm happy I did because it was a very enjoyable read.

  • you shouldn't compress image files because they don't compress any further and doesn't decrease the bandwidth. On the other hand, when you include files that doesn't compress, you waste CPU cycles trying to compress them.

  • I am using IIS 6.

    I want to compress single site content with the extensions i.e.. Js, css, gif.

    I tried exploring a lot on this but somehow it compresses all the sites instead of one.

    Please help if anyone one did it.

    Thanks
    chandra

  • I am working on a HTTPS client & server (java) via IIS6/ISAPI using JSON. The client is capable to send the json messages to the server to respond via IIS. Bear in mind, the message is not compressed and it works.

    However when the message is gzip compressed the IIS6 is unable to handle the compression data. I tried setting the IIS as mentioned above but it is not working. How do I debug the issue?

Comments have been disabled for this content.