Brian Cryer

 

Cry How To...


Enable HTTP Compression on an IIS Web Server


Page contents:

What is HTTP Compression?

HTTP Compression provides a simple means of dramatically reducing bandwidth usage. With HTTP Compression IIS compresses HTML (or strictly specific HTTP traffic) for those clients that are able to uncompress it.

HTTP Compression can only be enabled for IIS on a Windows server. The option for it is not present for the IIS server running on Windows XP.

Why use HTTP Compression?

The benefits of enabling HTTP Compression are reduced bandwidth usage and reduced download times for clients. This does come at a cost - increased processing at the server and the generation of additional temporary files at the server.

Compression should result in an average 30-70% reduction in bandwidth, and a corresponding reduction in download times for your visitors.

Enable HTTP Compression of Static files

Static files are those files that never change, such as html files (but not .aspx or .php which are dynamic and may yield different content each time).

To enable HTTP compression of static files:

  1. Whilst you should not need it, I would suggest taking a a backup copy of the file C:\Windows\System32\inetsrv\MetaBase.xml. If you need to undo the following steps the easiest and guaranteed way is to simply restore your copy of this file.
  2. Open Internet Information Services (IIS) Manager.
  3. Expand the server, right click “Web Sites” and select “Properties”
  4. On the “Service” tab, check:
    [√] Compress application files.
    You may want to consider checking:
    [√] Compress static files
    but see below "Enabling HTTP Compression of Dynamic files" first.
  5. I would recommend setting a maximum temporary directory size. The default is 95MB, which for my purposes has always been more than adequate, but see my notes below.
  6. Click [OK] to close the dialog.

Note:

  • When setting the maximum temporary folder size it is worth being aware of how IIS works when it comes to compression and how this temporary directory will be used. IIS compresses static files the first time they are requested. Subsequent requests for the file will return the already compressed version. The temporary folder is where IIS stores the compressed version of these files. If you have a large site then you may wish to increase the maximum size of the temporary folder.
  • Because files are only compressed on their first request this means that other than that initial hit, HTTP Compression of static files comes with virtually no processor overhead.
  • The default is for files of type .htm, .html and .txt file to be considered static.

Enable HTTP Compression of Dynamic files

Dynamic files are files which have the potential to generate different output each time they are requested.

To enable HTTP Compression of dynamic files repeat the steps above for enabling HTTP compression of static files, but when you reach the service tab step ensure that you tick: [√] Compress static files

Note:

  • By default only .asp, .dll and .exe files will be compressed.
  • Whilst for static files the files are compressed only once, the output from dynamic files is compressed for each request and not cached. There will therefore be a processor hit each time a file is requested. For this reason if your processor(s) are normally busy (say more than 70% utilization), HTTP Compression of dynamic files is not recommended.

Enabling HTTP Compression of .aspx files

The default out-of-the box configuration of IIS is that with HTTP Compression of dynamic files enabled it will only compress the output from .asp, .dll and .exe files.

The following process will add .aspx files to that list:

  1. Open a command prompt and type:
    Net stop iisadmin

    You will probably be prompted that this will stop other services. Enter “y” to allow it to continue the operation. Make a note of which services it stopped, because you may need to restart some of these manually.

  2. then type:
    cd c:\inetpub\adminscripts
    This takes you to the folder that contains the admin scripts needed.
     
  3. Enter:

    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"

    Note:

    • Each of the two lines above (starting cscript.exe ...) should be entered on a single line (so a total of two lines). They may have wrapped in the browser but each line is a single line.
    • To avoid copying mistakes a copy-and-paste of the above two lines might be best, but be sure to copy and run each one individually.
    • On each of these lines you are specifying ALL of the file types to be treated as dynamic. The example above specifies .asp, .dll, .exe and .aspx. To add .php to the list add "php" to the end of both lines.
    • If you want to see what file types are already set as dynamic then use:

      cscript.exe adsutil.vbs get W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions

  4. Next restart the web services:
    net start w3svc

    Starting w3svc will automatically restart the iisadmin service. If however when you did the “net stop” any of the following were listed then you will need to manually restart them:

    Simple Mail Transfer Protocol (SMTP) service
    net start smtpsvc
     
  5. Close the command prompt. You are all done.

These notes have been tested with IIS running on Windows 2003 Server



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.