Using HTTP Compression With IIS 5.0

By Peter A. Bromberg, Ph.D.
Printer - Friendly Version

Peter Bromberg

Internet Information Services (IIS) 5.0 introduces HTTP Compression, a new feature that compresses files before sending them across the network. HTTP Compression provides faster transmission of pages between the Web server and compression-enabled clients, compresses and caches static files, and performs on-demand compression of dynamically generated output. Using HTTP compression, some Web servers gain up to a 400% performance improvement. I have to confess that one of the reasons I've taken the time to assemble this information is that until very recently, although I've known about IIS Compression for a long time, I did not know that IIS can handle the "on the fly" compression of dynamic content. Certainly, as is the case with many Microsoft product features, the documentation on this is woefully inadequate!

HTTP Compression reduces the bandwidth needed to transfer files from the server to the browser. It helps to reduce per-page download time and improve performance for end-users. HTTP Compression uses standard GZIP and Deflate algorithms, which are built into Windows 2000 and Internet Explorer versions 4 and above. These compression and de-compression algorithms compress and cache static files.

Most developers are familiar with IIS HTTP 1.1 compression. Most developers, however, are NOT familiar with the fact that IIS 5.0 can compress dynamic content - the result of an ASP page that makes a custom database query as the result of a specific form POST and returns a dynamic, custom page with say, an HTML table of the results.

These algorithms also perform on-demand compression of dynamically generated responses before sending them over the network, and are again used to de-compress the static files and dynamic responses on an HTTP 1.1 supported client (Internet Explorer or My Computer, for example).

The first time a static file is requested by an HTTP 1.1 enabled client, IIS sends the file un-compressed to the client. IIS then saves a compressed copy of the static file in the designated temporary folder. The next time an HTTP 1.1 enabled client requests the file, IIS sends the compressed version from the temporary folder. IIS also keeps track of the original un-compressed versions of the static files. When the original static files are updated, IIS will update and re-compress the files in the temporary folder. Dynamic output from applications is not cached to the temporary folder; instead script output is compressed each time it is sent to a client.

Browsers that are not HTTP 1.1 compliant request and receive the files from IIS un-compressed. If you want to verify that Internet Explorer is configured to use the HTTP 1.1 protocol:

    Open the Internet Options property sheet. This is located under the Tools menu .

  1. Select the Advanced tab
  2. Under HTTP 1.1 settings, verify that "Use HTTP 1.1" is selected

The performance increase resulting from HTTP Compression is determined by a number of variables, such as processor power of the Web server and network bandwidth. The ideal situation to enable HTTP Compression is when you host a public web site that is accessed by clients using modems, or when there is a lot of static (.htm / .html) content. However, even if your site has almost all dynamic content (.asp, .jsp, .aspx, etc. ) you may find that provided you have the RAM and CPU power, HTTP Compression is worthwhile.


You should establish a performance baseline with Perfmon counters on your Web server before enabling HTTP compression. This helps determine if using HTTP Compression is appropriate for your particular situation.

Use System Monitor to log the % Processor Time counter of the Processor object over several days to establish a baseline. This counter has a Total instance and a separate instance for each processor in the system. (If your server has more than one processor, you should probably watch the individual processors as well as the total, to discover any imbalance in the workload).

After obtaining a performance baseline, enable HTTP compression on your server. Continue to log the value of these counters for an extended period, preferably several days. Compare the performance baseline values to the HTTP Compression enabled values. If the % Processor Time counter is constantly higher than 80%, then you should not use HTTP compression until you can upgrade your server.

How To Enable HTTP Compression

HTTP Compression can be enabled only on a server-wide basis. If you have multiple sites running on a single IIS 5.0 Web server, you'll be enabling HTTP Compression for all sites.

  1. From the Internet Services Manager, right-click the Computer icon, and select Properties.
  2. On the Internet Information Services tab, under Master Properties, select WWW Service.
  3. Click Edit, the WWW Service Master Properties property sheet should appear.
  4. Select the Service tab (see screen capture below).
  5. To compress static files for transmission to compression-enabled clients, select Compress static files. Selecting this option compresses and caches files with the extensions "htm," "html," and "txt."
  6. Type the path to a local directory in the Temporary folder text box, or use the Browse button to locate a directory where the compressed files will be kept.

    NOTE: The directory you choose in Step 6 must be on a local drive to the Web server, and it must be on an NTFS partition. The directory can not be shared, and it cannot be a compressed directory or on a compressed volume.

  7. To compress the dynamic output from applications for transmission to compression-enabled clients, select Compress application files. Selecting this option compresses and the dynamic output from applications with the file extensions "dll," "asp," and "exe."by default.To limit the maximum temporary folder size, select Limited to, and type a whole number in the MB field.

The WWW Service Master Properties property sheet

By default, maximum temporary folder size is set to unlimited. This works OK for Web servers with enough hard-disk storage for both the un-compressed version, in addition to the compressed version of static files stored in the temporary folder.

However, if running short of disk space is a concern, then select "Limited to". When the maximum temporary folder size is reached as configured by the MB field, IIS will delete 256 files to make room for new compressed files to be cached to the temporary folder. Configuring a temporary folder size too small can have an impact on performance because IIS will need to re-compress and re-cache static files, resulting in more CPU usage and hard drive access time.

Customizing Compression for additional File Types

The "compress static-files" option on the WWW Service Master Properties property sheet only compresses files with the extensions "htm," "html," and "txt" and the "compress application files" option on this property sheet only compresses the output from files with the extensions "dll," "asp," and "exe." These file name extensions are saved as parameters in the HcFileExtensions and HcScriptFileExtensions IIS metabase keys. You cannot customize these default parameters from the property sheet, but they are customizable by editing the metabase directly, as shown below.

The following examples show how to add file types to, or remove file types from the above stated list of compressible file types. The following steps need to be performed in addition to those listed above on how to enable HTTP Compression.

Example 1

The "compress static files option" is enabled. In addition to compressing files with the extensions "htm," "html," and "txt," you also decide to compress files with the extensions "ppt" and "xls." (You can choose to have IIS compress just about any type of file, static or dynamic, e.g. "cfm" "doc", etc.)

The commands listed in Step 3 below, replace the previously defined file extensions after the IIS Services are restarted.

NOTE: The new parameters ("ppt" and "xls") are not appended to the existing file extensions so you must also include the file types that were previously enabled using the WWW Service Master Properties property sheet.

  1. Open a command prompt window.
  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTP Compression on.
  3. Type in the following lines into the Command prompt Window:

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "ppt" "xls"

    cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "ppt" "xls"

    IISreset.exe /restart

Use Windows Explorer to watch the compressed versions of the files appear in the folder that you selected as the temporary folder on the WWW Service Master Properties property sheet. Remember, these files are only cached to the temporary folder after being requested by a client for the first time.

Example 2

The "compress application files" option has been enabled from the WWW Service Master Properties property sheet. By default, this compresses the dynamic output from files with the extensions "dll," "asp," and "exe." You want to also compress the output from files with the "aspx" extensions.

Therefore, we must duplicate the existing file extensions in order to preserve them, and also add the new one(s):

  1. Open a command prompt window.
  2. Within the command prompt window, navigate to \inetpub\AdminScripts for the server that you are enabling HTTP Compression on.
  3. Type in the following lines into the Command prompt Window:

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

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

    IISreset.exe /restart

Note: You can also make a batch file of the above by saving the lines in a text file "compressionOptions.bat". You can then simply double-click on this file in Windows Explorer.

If compression for both application files and static files is enabled, the procedure in Example 2 will not affect the static file settings, or the default settings from the WWW Service Properties property sheet.

Will Turning on Compression hurt my site, and will some browsers not be able to see my content?
No. In order to receive compressed content from IIS, the browser must send the correct "Accept-Encoding" request header. If this header is not present, IIS will simply send normal, uncompressed content. Provided you have the RAM and CPU power, turning on compression should only have beneficial effects. I have heard that some older Netscape browser get confused, but at this late stage of the game, that's really become a non-issue. Considering that the typical content compressed via GZip is only 10% to 15% of the size of the original uncompressed content, you don't need a degree in rocket science to figure out that the user is going to see the page a LOT FASTER.

NOTE: If you are using a custom compression component such as PABZlib, Xceed Streaming Compression, or NZlib, having IIS compression turned on will interfere with the ability to dynamically compress content using your component in any page with an extension that is mapped to IIS compression in the metabase. The solution is to give these files a custom extension (e.g. .asg or .aspg) and map this extension to the proper ISAPI filter in IIS Manager (such as ASP.DLL, for example).

We have reviewed what HTTP Compression is, how it works, and how to decide if you should use it. With HTTP Compression enabled, users of your Web site can experience dramitically improved download times if they are using HTTP 1.1 enabled clients. You should always test the performance of your server before deciding to enable HTTP Compression. We also discussed how to enable and further customize HTTP Compression on your Web server, and how to use IIS compression side - by -side with custom compression components. Native IIS compression technology does have some "gotchas". Starting in 2004, began using a product called ZipEnable for our data compression.  ZipEnable is a cost-effective solution from Port 80 Software that is both more flexible than native IIS compression, and fixes many of the inherent problems and bugs that the built- in IIS product has.

Peter Bromberg is a C# MVP, MCP, and .NET consultant who has worked in the banking and financial industry for 20 years. He has architected and developed web - based corporate distributed application solutions since 1995, and focuses exclusively on the .NET Platform.