Note: An HTTP client must initiate communication for compressed content by sending the appropriate HTTP Accept-encoding header. If a client is not capable of HTTP compression, it will not pass that header and IIS 7 will always return uncompressed content.

There are two different types of compression that IIS 7 uses:

Static Compression:

IIS 7 caches compressed static content in the path that is specified by the directory attribute, which increases compression performance by eliminating the need to recompress content that has already been compressed. After IIS 7 has compressed a file, subsequent requests are given the compressed copy of the file from the cache directory.

The staticCompressionEnableCpuUsage and staticCompressionDisableCpuUsage attributes specify when IIS 7 will compress static files based on CPU usage.

You should use static compression with files that do not typically change, such as HTML files (*.html, *.htm), text files (*.txt), Microsoft Office documents (*.doc, *.xls, *.ppt), etc. The size of these files can be reduced through compression, which reduces download times for client requests and reduces bandwidth on the server.

Note: Image files such as *.jpg and *.png files are also static files, but typically they do not benefit from HTTP compression because these image files are already compressed.

Dynamic Compression:

Unlike static compression, IIS 7 performs dynamic compression each time a client requests the content, but the compressed version is not cached to disk. This change is made because of the primary difference between static and dynamic content. Static content does not change. However, dynamic content is typically content that is created by an application and therefore changes often, such as Active Server Pages (ASP) or ASP.NET content. Since dynamic content should change often, IIS 7 does not cache it.

The dynamicCompressionEnableCpuUsage and dynamicCompressionDisableCpuUsage attributes specify when IIS 7 will compress dynamic files based on CPU usage.

Compatibility

The staticCompressionIgnoreHitFrequency attribute was added in IIS 8.5.

IIS 8.0

The <httpCompression> element was not modified in IIS 8.0.

IIS 7.5

In IIS 7.5, the default value for the minFileSizeForComp attribute has been changed, and the dynamicCompressionBufferLimit attribute was added.

IIS 7.0

The <httpCompression> element was introduced in IIS 7.0.

IIS 6.0

The <httpCompression> element replaces the following IIS 6.0 metabase properties:

HcCacheControlHeader

HcCompressionDirectory

HcDoDiskSpaceLimiting

HcExpiresHeader

HcMaxDiskSpaceUsage

HcMinFileSizeForComp

HcNoCompressionForHttp10

HcNoCompressionForProxies

HcNoCompressionForRange

HcSendCacheHeaders

Setup

HTTP compression is usually available on the default installation of IIS 7 and later. However, only static compression is installed by default. To install static or dynamic compression, use the following steps.

Windows Server 2012 or Windows Server 2012 R2

On the taskbar, click Server Manager.

In Server Manager, click the Manage menu, and then click Add Roles and Features.

In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.

Windows Server 2008 or Windows Server 2008 R2

In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.

On the Select Role Services page of the Add Role Services Wizard, select DynamicContent Compression if you want to install dynamic compression and Static Content Compression if you want to install static compression, and then click Next.

On the Confirm Installation Selections page, click Install.

On the Results page, click Close.

Windows Vista or Windows 7

On the taskbar, click Start, and then click Control Panel.

In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.

In the Connections pane, select the server, and then double-click Configuration Editor.

In the Configuration Editor, for the section, select system.webServer, and then select httpCompression.

For staticCompressionIgnoreHitFrequency, enter True to disable the behavior that a static file is compressed only if it is hit a certain number of times within a time period, or enter False to enable the behavior.

In the Actions pane, click Apply.

Configuration

Attributes

Attribute

Description

cacheControlHeader

Optional string attribute.

Specifies the directive that IIS adds to the Cache-Control header that overrides the HTTP Expires header. This attribute ensures that older clients and proxy servers do not attempt to cache compressed files. To enable this setting, you must set the sendCacheHeaders attribute to true. The WWW service must be restarted before changes to this property take effect.

The default value is max-age=86400.

directory

Optional string attribute.

Specifies the directory where compressed versions of static files are temporarily stored and cached.

Specifies whether a limit exists for the amount of disk space that all compressed files, which are stored in the compression directory specified by the directory attribute, can occupy.

The default value is true.

dynamicCompressionBufferLimit

Optional uint attribute.

Specifies the maximum amount of dynamically compressed data that IIS will buffer before flushing the buffer to a client. This decreases the amount of memory that is necessary to perform dynamic compression.

Note: This attribute was added in IIS 7.5.

The default value is 65536.

dynamicCompressionDisableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization at which dynamic compression will be disabled.

Note: This attribute acts as an upper CPU limit at which dynamic compression is turned off. When CPU utilization falls below the value specified in the dynamicCompressionEnableCpuUsage attribute, dynamic compression will be re-enabled.

The default value is 90.

dynamicCompressionEnableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization below which dynamic compression will be enabled. The value must be between 0 and 100. Average CPU utilization is calculated every 30 seconds.

Note: This attribute acts as a lower CPU limit below which dynamic compression is turned on. When CPU utilization rises above the value specified in the dynamicCompressionDisableCpuUsage attribute, dynamic compression will be disabled.

The default value is 50.

expiresHeader

Optional string attribute.

Specifies the content of the HTTP Expires header that is sent with all requested compressed files, together with the Cache-Control header specified in the cacheControlHeader attribute. This combination of headers ensures that older clients and proxy servers do not try to cache compressed files. To enable this setting, you must set the sendCacheHeaders attribute to true. The World Wide Web Publishing Service (WWW service) must be restarted before changes to this property take effect.

The default value is Wed, 01 Jan 1997 12:00:00 GMT.

maxDiskSpaceUsage

Optional uint attribute.

Specifies the number of megabytes of disk space that compressed files can occupy in the compression directory. When the space used by compressed files exceeds 90 percent of the value in this attribute, IIS deletes the least recently used files until a 90-percent usage level is reached.

Note: In IIS 6.0, this limit was expressed in bytes; in IIS 7, it is expressed in megabytes. In IIS 7 the limit is applied per application pool.

The default value is 100.

minFileSizeForComp

Optional uint attribute.

Specifies the minimum number of kilobytes a file must contain in order to use on-demand compression.

The default value for IIS 7.5 is 2700; for IIS 7.0 the default value was 256.

noCompressionForHttp10

Optional Boolean attribute.

Specifies whether compression is disabled for requests that contain an HTTP 1.0 version number.

Note: Some HTTP 1.0 clients do not handle the caching of compressed objects correctly. You can use this setting to avoid returning a compressed file to a client that cannot decompress it.

The default value is true.

noCompressionForProxies

Optional Boolean attribute.

Specifies whether the HTTP 1.1 response is disabled for compression requests that come through proxy servers.

Note: Some HTTP proxy servers do not handle the caching of compressed objects correctly. You can use this setting to avoid returning a compressed file to a proxy server that cannot decompress it.

The default value is true.

noCompressionForRange

Optional Boolean attribute.

Specifies whether compression is disabled for HTTP requests that include the Range header.

Note: Some clients cannot handle range requests correctly. You can use this setting to avoid returning a compressed file to a client that cannot decompress it.

The default value is true.

sendCacheHeaders

Optional Boolean attribute.

Specifies whether the headers configured in cacheControlHeader and expiresHeader are sent with each compressed response.

The default value is false.

staticCompressionDisableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization at which static compression is disabled. The value must be between 0 and 100. Average CPU utilization is calculated every 30 seconds.

Note: This property acts as an upper CPU limit at which static compression is turned off. When CPU utilization falls below the value specified in the staticCompressionEnableCpuUsage attribute, static compression will be reenabled.

The default value is 100.

staticCompressionEnableCpuUsage

Optional uint attribute.

Specifies the percentage of CPU utilization at which static compression is enabled. The value must be between 0 and 100. Average CPU utilization is calculated every 30 seconds.

Note: This property acts as a lower CPU limit below which static compression is turned on. When CPU utilization rises above the value specified in the staticCompressionDisableCpuUsage attribute, static compression will be disabled.

The default value is 50.

staticCompressionIgnoreHitFrequency

Optional Boolean attribute.

If True, disables the behavior that a static file is compressed only if it is hit a certain number of times within a time period. You may encounter circumstances In which you want static content always to be compressed to lower bandwidth usage. For example, you may want to always compress static content when a system employs a load balancer with edge caching between a Web server and the requester, causing an uncompressed file to be cached at the edge server because subsequent requests would not reach the Web server.

If the behavior is not disabled, a hit rate of greater than or equal to two hits in 10 seconds will result in compression of the static content. A lesser hit rate would result in the content not being compressed.

Configuration Sample

The following default <httpCompression> element is configured in the ApplicationHost.config file in IIS 7. This configuration section inherits the default configuration settings unless you use the <clear> element.

Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.