The IIS compression Series
Part 1 Starting with this article, I'll show how to get the most out of the compression features built into IIS 7 and IIS 6. This first article focusses specifically on IIS 7.
Part 2 In this article, Matt Perdeck shows how to make the most out of IIS 6 compression.
Part
3 In this article, Matt Perdeck shows how to enable compression in your development environment, so you can keep track of how large your
pages will be as they travel over the Internet to the browser.
Introduction
As of July 2011, IIS 6 is still used by 72.4% of all the websites that use Microsoft-IIS (source).
Unfortunately, configuring compression on IIS 6 is far from straight forward. It involves four steps:
- Switch on compression in the IIS Manager;
- Set permissions on the folder where compressed static files are cached;
- Update the metabase;
- Reset the IIS server.
Let's go through each step in turn.
Switch on compression in the IIS Manager
This consists of the following steps:
- Start IIS manager: Click on Start | Administrative Tools | Internet Information Services (IIS) Manager.
- 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 the IIS manager.
- Expand your server. Right-click on the Web Sites node and click on Properties | Service.
- 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.
- Select Compress static files.
- 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.
- Set a maximum size for the temporary directory.
- 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.
- Right-click on the folder and click on Properties | Security.
- Click on the Add button and add the IIS_WPG group, or the identity of the application pool.
- Allow Full Control to the identity you just added and click on OK.


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:
- 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.
- You'll normally find the metabase in directory
C:\Windows\system32\inetsrv, in file metabase.xml. Open that file with a text editor.
- Find the
IIsCompressionScheme elements. There should be two of these: one for the deflate compression algorithm and one for gzip.
- 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:
- 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.
- 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:
- 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:
- 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.
- Save the file.
- 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:
- Open command prompt and change the directory to
C:\Inetpub\AdminScripts
- Run the following command:
More information about adsutil.vbs is 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:
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.
In the next article, you'll see how to enable compression in your development environment - so you can keep track of the actual size of your new web pages as they will go over the wire to the browser.
If you enjoy 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. Or visit my web site ASP.NET Performance.
The IIS compression Series
Part 1 Starting with this article, I'll show how to get the most out of the compression features built into IIS 7 and IIS 6. This first article focusses specifically on IIS 7.
Part 2 In this article, Matt Perdeck shows how to make the most out of IIS 6 compression.
Part
3 In this article, Matt Perdeck shows how to enable compression in your development environment, so you can keep track of how large your
pages will be as they travel over the Internet to the browser.
About Matt Perdeck
 |
Matt has over 6 years .NET and SQL Server development experience. Before getting into .Net, he worked on a number of systems, ranging from the largest ATM network in The Netherlands to embedded software in advanced Wide Area Networks. He has lived and worked in Australia, The Netherlands, Slovakia a...
This author has published 4 articles on DotNetSlackers. View other articles or the complete profile here.
|
Other articles in this category
IIS FTP User Isolation - Week 46
This week we walk through the five isolation modes to gain a full understanding of the IIS FTP metho...
FTP Firewall settings, Active vs. Passive, and FTPS Explicit vs. Implicit Week 47
Understanding Active and Passive mode for FTP is useful for troubleshooting and ensuring that the fi...
Q&A. What’s new in IIS8, Perf, Indexing Service–Week 49
This week I'm taking Q&A from viewers, starting with what's new in IIS8, a question on enable32BitAp...
IIS FTP Troubleshooting - Week 48
This lesson covers ways to troubleshoot IIS FTP. When it works, it works well, but if you run into i...
Q&A. DNS Load Balancing, Google and Geo-location, CDNs-Week 50
This week answers two Q&A questions from viewers. DNS Load Balancing and then some discussion and a ...
You might also be interested in the following related blog posts
Web Deployment Tool released to web (RTW)
read more
Don’t use Response.End() with OutputCache
read more
Kobe - Oh Dear Lord Why?!
read more
Trip Report from Gov 2.0 Camp
read more
IIS 7 Compression. Good? Bad? How much?
read more
"Software is everything. (It also sucks.)" - What does this have to do with DotNetNuke?
read more
URL Rewrite for IIS - SEO Friendly URLs love it !
read more
Silverlight Controls
read more
ASP.NET tab in IIS, more dangerous than it first appears!
read more
WCF REST Configuration for ASP.NET AJAX and plain REST Services
read more
|
|
Please login to rate or to leave a comment.