What is HTTP compression?

Text files transferred by HTTP such as css, html, javascript etc are highly compressible – by their nature they can be compressed to a fraction of their original size quickly without much webserver CPU load.

IIS can perform this compression on your original uncompressed css/html/javascript source files and transfer the compressed content to people’s web browsers. Their browsers then expand the compressed files whilst browsing saving a great deal of bandwidth/download time. Important to note is that the people browsing are never aware that they’re browsing a compressed website.

Should I bother?

Brightminds.co.uk homepage download size shrank from 660KB to less than 400KB. This saving however includes image downloads and the real compression saving takes the page weight from 77KB down to only 12KB. Thus less than a sixth of the page size is downloaded by a browser at a tiny CPU load cost. End result? Since expanding the page on the user’s browser requires practically no CPU load, everyone’s browsing experience is significantly faster. But what about the webserver CPU cost? It’s far smaller than the CPU cost of uploading a further 64KB to the user.

The Bottom Line – HTTP compression is free and quick to enable. If you’re not using HTTP compression, you’re compromising your reader’s/customer’s experience and burning bandwidth.

Lets enable it!…

There’s a great deal of conflicting articles on the web about how to enable compression correctly in IIS6. Some say that you will need to edit the metabase whilst others say a simple cscript will do all. I’ve found you’ll need to do both and I’ll outline how below…

Make a backup of your existing IIS6 configuration by opening Computer Management, expanding IIS and then right clicking on it to All tasks – Backup/restore configuration.

Backing up IIS configuration

Backing up IIS configuration

Click on Web Service Extensions within IIS, right click and select to add a new web service or extension. Call it HTTP Compression and add %systemroot%\System32\inetsrv\gzip.dll as a required file. Select to allow the extension and click OK.

New IIS Service or Extension

New IIS Service or Extension

Within IIS right click on ‘Websites’ and go to Properties. Click on the Service tab and tick the box to ‘Compress application files’ (this will compress files sent with the extensions .asp, .aspx etc) and also tick the box to ‘Compress static files’ (compressing .html, .css etc).

Enabling Compression in IIS6

Enabling Compression in IIS6

If you want to specify a different directory to store the temporary files to then do. Specify a storage limit, although brightminds.co.uk have up to 250,000 compressible hits a day I’ve never seen the compression directory exceed a few MB. 1GB will be more than enough. Click OK.

Now we need to specify which file types are compressed by IIS. Individually copy, paste and run the following commands into the Run box.

cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/deflate/HcFileExtensions htm html txt css js
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcFileExtensions htm html txt css js
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/deflate/HcScriptFileExtensions asp dll exe aspx asmx php
cscript c:\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/Filters/Compression/gzip/HcScriptFileExtensions asp dll exe aspx asmx php

These commands enable the compression formats deflate and gzip for the specified file types. So for example the last command enables gzip compression for files with the extensions .asp, .dll, .exe, .aspx, .asmx and .php. You may ask why not compress .jpg image types and indeed all web content. Simple answer – text files compress quickly and exceedingly well, images/videos etc don’t.

Right click on IIS again in Computer Management and stop all IIS services.

Now Run the following command from the Run box to edit the IIS Metabase…

Notepad %systemroot%\system32\inetserv\metabase.xml
Editing the IIS Metabase

Editing the IIS Metabase

Find/search for the line that contains the following tag – ‘<IIsCompressionScheme’. There should be two of them, one referring to gzip and another for deflate (the two compression methods). HcFileExtensions should state the static file extensions we want to compress – htm, html, txt, css and js. Likewise HcScriptFileExtensions should state the dynamic file extensions to be compressed – asp, dll, exe, aspx, asmx and php.

What we need to do is edit HcDynamicCompressionLevel=”0″ for both gzip and deflate to be HcDynamicCompressionLevel=”9″. This defines the compression level on a scale between 0 and 10. 0 doesn’t compress and 10 uses far too much CPU load compressing, 9 is generally the best option.

Double check you have changed HcDynamicCompressionLevel for both gzip and deflate and save the file changes (File > Save).

Again in Computer Management Right click on IIS Computer Management and start all IIS services.

Your IIS web server should now be serving a compressed website. Double check it by entering your domain into http://www.whatsmyip.org/http_compression/.

  • Share/Bookmark

3 Responses to “Getting HTTP gzip compression working in IIS6”

  1. Alan Flatley says:

    Thanks! Worked 100%

  2. smokingpagoda says:

    Hey cool looking blog but it is a bit weird looking in my K-meleon browser. Looks great besides that!

  3. Peter says:

    perfect article! Thanks from Switzerland

Leave a Reply