HTTP compression can provide significant performance improvements on websites serving both static and dynamic content. The concept is simple and offers faster page downloads for the user and reduced bandwidth costs for you. Using gzip, Internet Information Services (IIS) can compress the content before it is sent from the server to compression-enabled clients.
How much compression are we talking about? Typically, I see about 70% compression on uncompressed content such as HTML, CSS, PHP, etc. Image files, which are usually already compressed, don’t benefit from HTTP compression.
IIS 5 was notoriously bad at compression, and IIS 7 (Server 2008/Vista) has it enabled by default. In the middle is IIS 6.0 on Windows Server 2003, which has great native compression built in but it’s disabled by default.
Enabling compression is not a trivial matter, nor is it overly complex, but it does take a bit of tinkering under the hood which many web admins prefer to avoid if possible. However, the benefits outway the cost so let’s do it.
Preperation
First, be prepared to restart IIS after completing these steps, so pick a good time before you begin.
We’re going to be editing the IIS metabase so we must configure IIS to allow us to save the changes. Otherwise IIS has this file locked by default. In Internet Information Services (IIS) Manager right-click on the web server and go to Properties. Tick the Enable Direct Metabase Edit checkbox like shown below then click Apply.
Enabling IIS Compression
Right-click on the Web Sites node in IIS Manager and go to Properties. In the Web Sites Properties dialog click the Service tab to get to the screen in Figure 2. We have a few options here but typically we’re going to go with the selected options shown. Change the Temporary directory to something else if you don’t like the default, but be certain that it’s a local NTFS partition and not marked for compression.
Adding the Web Service Extension
Next we’ll add the Web Service Extension in IIS Manager. Click the Web Service Extensions node and then the Add a new Web service extension link in the right pane. In the New Web Service Extension dialog box enter the name of the extension, anything you like, but most people go with HTTP Compression. Then add gzip.dll to the required files as shown in Figure 3. Your path may be different than shown here, but for most servers this is typical. Tick the Set extension status to Allowed and then click OK.
Editing the Metabase
We’re almost done. We just need to edit the metabase so IIS knows which file types to compress. This is a bit tricky because we must also know whether those file types are going to be static or dynamic. The issue here is that static files are going to get cached in the temporary directory whereas dynamic content is going to get compressed on every request.
The metabase is a text file located in the c:\windows\system32\inetpub\ directory. First, locate MetaBase.xml and make a backup copy in case something goes horribly wrong. Then, open MetaBase.xml in a text editor and locate the IIsCompressionScheme tag, but be careful because there are two sections here: one for deflate and one for gzip. We want the gzip section.
The tags we’re primarily interested in are:
- HcDynamicCompressionLevel: Specifies the compression level from 1 to 10, with 10 being the highest compression level and requiring the most CPU. If your server is heavily loaded then you may want to reduce this level.
- HcFileExtensions: Static content to compress. In the example here I’m using htm, html, txt, xml, css, and js.
- HcScriptFileExtensions: Dynamic content to compress. In the example here I’m using asp, dll, exe, aspx, asmx, axd, and php. The axd extension is specifically for Telerik RadControls.
After we have those settings complete we can save the file.
HcCompressionDll=”%windir%\system32\inetsrv\gzip.dll”
HcCreateFlags=”1″
HcDoDynamicCompression=”TRUE”
HcDoOnDemandCompression=”TRUE”
HcDoStaticCompression=”TRUE”
HcDynamicCompressionLevel=”10″
HcFileExtensions=”htm
html
txt
xml
css
js”
HcOnDemandCompLevel=”10″
HcPriority=”2″
HcScriptFileExtensions=”asp
dll
exe
aspx
asmx
axd
php”
>
Fixing a Bug
There’s one more issue we need to fix before we’re done. Microsoft knowledge base article 319384 identifies a problem with “Pages do not expire as expected after you change Web site content”.
The instructions in the article say to run this command to fix the problem:
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/Parameters/HcCacheControlHeader “max-age=0″
It doesn’t hurt to double check things because computers are stupid…
After running this command my MetaBase.xml file still contained the old setting of max-age=86400, so I just made the change manually and continued on.
Restart and Test
Now our configuration is complete. We just need to restart IIS and then test if our compression is really working. To restart IIS you can right-click the web server in IIS Manager and then click All Tasks, and then Restart IIS… Or use the iisreset /restart command if you’re a command prompt junkie.
To test if our web server is actually compressing content go to either PipeBoost or Port80 Software.











Sun, Jul 20, 2008
1 Comment