Using IIS 6.x Native Content Compression

Over the past few days, I have been discovering that we had a shit load of data being shipped around the network etc when a page was requested via our CMS.  I decided to look into using HTTP Content Compression to help speed up the client page loads and also to reduce bandwidth.  I was researching a few products, especially httpZip which seems to be the choice of the pros, but in the end I decided on trying out native compression which comes with IIS 6.xMicrosoft didn’t make it easy to just switch on and bam you have compressed content so hopefully this will help you get started on how to get it all working etc.

1. Open IIS Manager

2. Right-Click on Web Service Extensions select “Add a new Web Service extension”

3.  Extension Name = HTTP Compression (or whatever you want as long as it makes sense and identifiable)
     3.1 Click Add to add the Required File
     3.2 Locate C:\WINDOWS\system32\inetsrv\gzip.dll

Well, you would think that was it, it’s not…lovely..so we continue.

1. Right-Click on Web Sites

2. Select Service Tab

3. Check the following; “Compress Application Files” and “Compress Static Files” within the HTTP compression section.

Again, you would think that was it…..well nearly…now we need to get down and dirty with the IIS Metabase….strap on some protection and here we go..

1. Stop IIS Admin Service and its associated dependencies.

2. Open the Metabase.xml file (C:\WINDOWS\system32\inetsrv\Metabase.xml)

3. Search for “gzip” in the file and stop when you reach the <IIsCompressionScheme> node.  (there are actually two of these nodes and a plural node.  You can safely ignore the plural node for this as we are concentrating on the two singular nodes here).

4. Change the HcDynamicCompressionLevel to level 9 – it has a scale of 0-10 but a highest level of 10 can kill CPU etc and Level 9 Compression is alledgedly as good as 10 with less load on the CPU so use that.

5.  The next step is to add what you want to be included within the compression stream by adding the available file extensions (not MIME types) to the HcFileExtensions node.  They entries are seperated by CR/LF and 3 tabs.  An example entry can be seen here:

<IIsCompressionScheme Location =”/LM/W3SVC/Filters/Compression/deflate”
  HcCompressionDll=”%windir%\system32\inetsrv\gzip.dll”
  HcCreateFlags=”0″
  HcDoDynamicCompression=”TRUE”
  HcDoOnDemandCompression=”TRUE”
  HcDoStaticCompression=”TRUE”
  HcDynamicCompressionLevel=”9″
  HcFileExtensions=”htm
   js
   css
   jpg
   gif
   xml
   html
   txt”
  HcOnDemandCompLevel=”10″
  HcPriority=”1″
  HcScriptFileExtensions=”asp
   cfm
   aspx
   dll
   exe”
 >
</IIsCompressionScheme>
<IIsCompressionScheme Location =”/LM/W3SVC/Filters/Compression/gzip”
  HcCompressionDll=”%windir%\system32\inetsrv\gzip.dll”
  HcCreateFlags=”1″
  HcDoDynamicCompression=”TRUE”
  HcDoOnDemandCompression=”TRUE”
  HcDoStaticCompression=”TRUE”
  HcDynamicCompressionLevel=”9″
  HcFileExtensions=”htm
   js
   css
   jpg
   gif
   xml
   html
   txt”
  HcOnDemandCompLevel=”10″
  HcPriority=”1″
  HcScriptFileExtensions=”asp
   cfm
   aspx
   dll
   exe”
 >

In the above example, there is probably no reason or worth in trying to compress GIF/JPG as they are already compressed, but I was testing here and thought…feck it, your smart enough to realise this and would have ommitted them anyway 😉

OK, in all reality that is it……..erm “Hold on Feersum!!!!, my website isn’t serving pages anymore?!”   Oh yeah! your damn right…man,you’re sharp…. here’s the info you need….

You need to restart the IIS Admin Service and its associated dependencies and to be safe run an iisreset from a Command Prompt.

If you have followed all of these steps like the little lapdogs you are, your site will now be serving Compressed Content to the masses and hopefully, nay willfully be serving faster content and page loads to your minions.

Once thing I couldn’t get working, or couldn’t see it working from logs etc was “is it compressing my dynamic content such as ASP(.NET)/CFM etc?”; the answer seems to be it wasn’t – event though I told it to, and if you want that capability you will have to use httpZip or alike which actually has that capability in built especially for ColdFusion and problems related to <CFHTTP> and <CFSCHEDULE>.

So folks that’s it, hope you find it useful!!

Happy compressing 😉

 Feersum.

Advertisements