Thursday, March 26, 2009

Configuring gzip/deflate compression on IIS

An easy way to improve website performance, especially for low-bandwidth viewers, is to use compression to get the data to the user faster. The text portion of web pages (HTML, Javascript, CSS, etc.) compresses very well (90% or so) so the speedups can be significant. The user's web browser needs to support the compression method, this is done with the Accept-Encoding header that the browser will send to the server if it supports compression, for example, the major browsers support deflate and gzip: "Accept-Encoding: gzip, deflate"

Static content can be compressed and then cached, only updating when the original files are changed, so it takes very little CPU usage to implement and it's pretty much a no-brainer to enable. Dynamic content (PHP, ASP.NET, etc.) can also be compressed, but since it is compressed separately for every request, it can take up significant amounts of CPU utilization.

Below is a quick guide to enable HTTP compression in IIS:
  • Open up IIS manager and open up the properties for all web sites.
  • Under the service tab, select the "Compress static files" and enter the value of the Temporary directory where the cached files will be kept. In addition, you should limit the temporary directory size to 1 GB or so.
  • This will enable compression for .txt, .htm and .html files. However, .js and .css files can often be just as large as the HTML files.
  • To enable compression for other extensions, you'll need to edit the Metabase. I recommend using Metabase Explorer for this. You'll need to edit the W3SVC\Filters\Compression\gzip\HcFileExtensions key and change it from "htm,html,txt" to "htm,html,txt,js,css"
  • Now restart IIS to make the changes effective.
For more details, see the following url. This details how to turn it on for specific websites and other configuration options.

No comments: