Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / IIS

Making the most out of IIS compression - Part 2: Configuring IIS 6 compression

4.69/5 (7 votes)
24 Aug 2011CPOL6 min read 30K  
This two part series shows how to get the most out of the compression features built into IIS 7 and IIS 6. This second article focuses specifically on IIS 6 compression.

Parts in this series

Introduction

In part 1 of this series, we saw how to use compression in IIS 7.

As of August 2011, IIS 7's predecessor, IIS 6, is still used by 71.2% of all the websites that use Microsoft-IIS (source). Additionally, using compression in IIS 6 is a lot harder than in IIS 7. Hence this article on IIS 6 compression.

This article is based on chapter 10 Compression of my book ASP.NET Site Performance Secrets.

If you like this article, please vote for it.

Contents

Getting started

Unfortunately, configuring compression on IIS 6 is far from straightforward. It involves four steps:

  1. Switch on compression in IIS Manager;
  2. Set permissions on the folder where compressed static files are cached;
  3. Update the metabase;
  4. Reset IIS server.

Let's go through each step in turn.

Switch on Compression in IIS Manager

This consists of the following steps:

  1. Start IIS Manager: Click on Start | Administrative Tools | Internet Information Services (IIS) Manager.
  2. Backup the metabase: Right-click on your server and then click on All Tasks | Backup/Restore Configuration. Click on the Create Backup button, enter a name for your backup, such as today's date, and click on OK. Finally, click on Close to get back to IIS Manager.
  3. Expand your server. Right-click on the Web Sites node and click on Properties | Service.
  4. Image 1

  5. If your server has enough spare CPU capacity, select Compress application files. Because there is no caching for dynamic files of compressed content, this will cause IIS to compress dynamic files on the fly for every request. As a result, dynamic file compression takes more CPU than compressing static files.
  6. Select Compress static files.
  7. The temporary directory is where compressed static files are cached. Leave the default for Temporary directory. Or enter a different directory, for example, if your system drive is low on space. Make sure it sits on an uncompressed and unshared local NTFS volume.
  8. Set a maximum size for the temporary directory.
  9. Click on OK.

Set permissions on the folder where compressed static files are cached

For static compression to work, the IIS_WPG group or the identity of the application pool must have Full Control access to the folder where the compressed files are stored.

Unless you changed the folder in the previous step (in the Temporary directory field), it will be at C:\WINDOWS\IIS Temporary Compressed Files.

  1. Right-click on the folder and click on Properties | Security.
  2. Click on the Add button and add the IIS_WPG group, or the identity of the application pool.
  3. Image 2

  4. Allow Full Control to the identity you just added and click on OK.
  5. Image 3

IIS_WPG or IUSR_{machinename}?

There is conflicting advice on various websites as to whether you should give the IIS_WPG group or the IUSR_{machinename} account access to the folder where the compressed files are stored. However, my testing with a clean install of Windows Server 2003 and IIS 6 has shown that IIS 6 will only compress static files if the IIS_WPG group has Full Control access to that folder, irrespective of the level of access by IUSR_{machinename}.

Update the metabase

Next modify the metabase:

  1. Get IIS to allow you to edit the metabase. In IIS Manager, right-click on your IIS server near the top of the tree on the left-hand side. Click on Properties, check Enable Direct Metabase Edit, and click on OK.
  2. You'll normally find the metabase in the directory C:\Windows\system32\inetsrv, in file metabase.xml. Open that file with a text editor.
  3. Find the IIsCompressionScheme elements. There should be two of these: one for the deflate compression algorithm and one for gzip.
  4. In both the elements, extend the HcFileExtensions property with the extensions you need for static files used in your pages, such as .css and .js. You will wind up with something like the following:
  5. HcFileExtensions="htm
    html
    css
    js
    xml
    txt"

    Keep in mind that there is no point in including image files here such as .gif, .jpg, and .png. These files are already compressed because of their native format.

  6. Also, in both elements, extend the HcScriptFileExtensions property with the extensions you need for dynamic files, such as .aspx. You will wind up with something like the following:
  7. HcScriptFileExtensions="asp
    dll
    exe
    aspx
    asmx
    ashx"
  8. The compression level for dynamic files is set by the HcDynamicCompressionLevel property in both IIsCompressionScheme elements. By default, this is set to zero, which is too low. The higher you set this, the better the compression but the greater the CPU usage. You might want to test different compression levels to see which one gives you the best tradeoff between CPU usage and file size. Start testing at a low compression level and then increase this until CPU usage gets too high. The compression level can be between 0 and 10:
  9. HcDynamicCompressionLevel="1"
  10. The compression level for static files is set by the HcOnDemandCompLevel property in both IIsCompressionScheme elements. By default, this is set to 10, meaning maximum compression. Because compressed static files are cached (so that static files are not compressed for each request), this causes little CPU usage. As a result, you will want to stick with the default.
  11. Save the file.
  12. Disallow editing of the metabase. Right-click on your IIS server, click on Properties, uncheck Enable Direct Metabase Edit, and click on OK.

You'll find a full list of the available metabase properties here.

Instead of editing the metabase directly, you can run the adsutil.vbs utility from the command line to change the metabase. This allows you to write a script so you can quickly update a number of servers. For example, setting HcDoStaticCompression to true will enable static compression. This is done as follows:

  1. Open command prompt and change the directory to C:\Inetpub\AdminScripts
  2. Run the following command:
    cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

More information about adsutil.vbs is available here.

Reset the IIS server

Finally, reset the server, so that it picks up your changes. Right-click on your IIS server and then click on All Tasks | Restart IIS.

Alternatively, open a command prompt and run:

iisreset

Static files are not always served compressed

If a static file is requested and there is no compressed version of the file in the temporary directory where compressed static files are cached, IIS 6 will send the uncompressed version of the file. Only once that's done does it compress the file and store the compressed version in the temporary directory, ready to be served in response to a subsequent request for the file.

Summary

In this article, we saw how enabling compression in IIS 6 involves four steps - switching on compression, setting permissions so compressed static files can be cached, updating the metabase, and finally resetting the IIS 6 server.

If you enjoyed this series and want to know the full story on how to improve ASP.NET site performance, from database server to web server to browser, consider my book ASP.NET Site Performance Secrets.

License

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