HTTP 圧縮 <httpCompression>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<httpCompression> 要素は、インターネット インフォメーション サービス (IIS) 7.0 の HTTP 圧縮を指定します。HTTP 圧縮は、圧縮ファイルを受け取ることができるクライアント ブラウザーと IIS 間の転送時間を高速化します。

: HTTP クライアントは、適切な HTTP Accept-encoding ヘッダーを送信することにより、圧縮されたコンテンツの通信を開始する必要があります。クライアントが HTTP 圧縮をサポートしない場合は、このヘッダーを渡さないため、IIS 7.0 は常に圧縮されていないコンテンツを返します。

IIS 7.0 で使用する圧縮には 2 つの種類があります。

  • 静的な圧縮 :

    IIS 7.0 では、directory 属性によって指定されているパスの圧縮された静的コンテンツをキャッシュします。これにより、既に圧縮されたコンテンツを再圧縮する必要がなくなるため、圧縮パフォーマンスが向上します。IIS 7.0 がファイルを圧縮すると、後続の要求には、キャッシュ ディレクトリからファイルの圧縮コピーが提供されます。

    staticCompressionEnableCpuUsage 属性と staticCompressionDisableCpuUsage 属性により、IIS 7.0 が CPU の使用率に基づいて静的ファイルを圧縮する時期が指定されます。

    静的圧縮は、HTML ファイル (*.html、*.htm)、テキスト ファイル (*.txt)、Microsoft Office 文書 (*.doc, *.xls, *.ppt) など、通常は変更されないファイルに使用してください。これらのファイルは圧縮によってサイズが縮小されるため、クライアント要求のダウンロード時間を短縮して、サーバーの帯域幅を削減できます。

    : *.png や *.png などの画像ファイルも静的ファイルですが、これらの画像ファイルは既に圧縮されているため、通常は HTTP 圧縮によるメリットはありません。

  • 動的な圧縮 :

    静的圧縮とは異なり、動的圧縮は、クライアントがコンテンツを要求するたびに実行されますが、圧縮されたバージョンはディスクにキャッシュされません。この変更は、静的コンテンツと動的コンテンツの根本的な違いによるものです。静的コンテンツは変化しません。しかし、動的コンテンツは、Active Server Pages (ASP) または ASP.NET コンテンツなど、通常、アプリケーションによって作成されるコンテンツであるため、頻繁に変化します。動的コンテンツは頻繁に変化するため、IIS 7.0 はキャッシュしません。

    dynamicCompressionEnableCpuUsage 属性と dynamicCompressionDisableCpuUsage 属性により、IIS 7.0 が CPU の使用率に基づいて動的ファイルを圧縮する時期が指定されます。

IIS 7.0 では、次の 2 種類の業界標準の圧縮方式をサポートしてます。

これら 2 つの各圧縮形式は、<httpCompression> 要素の <schemes> 要素を使用して有効にできます。

: <httpCompression> 要素では、インターネット インフォメーション サービス (IIS) 7.0 の HTTP 圧縮設定を指定しますが、<urlCompression> 要素では、URL 名前空間で圧縮を有効にするかどうかを指定します。

互換性

  IIS 7.0 IIS 6.0
注意 <httpCompression> は IIS 7.0 で新たに導入された要素です。 <httpCompression> 要素は、IIS 6.0 の次のメタベース プロパティに代わるものです。

HcCacheControlHeader
HcCompressionDirectory
HcDoDiskSpaceLimiting
HcExpiresHeader
HcMaxDiskSpaceUsage
HcMinFileSizeForComp
HcNoCompressionForHttp10
HcNoCompressionForProxies
HcNoCompressionForRange
HcSendCacheHeaders

セットアップ

HTTP 圧縮は、通常、IIS 7.0 の既定のインストールに含まれていますが、静的圧縮だけが既定でインストールされます。静的圧縮または動的圧縮をインストールするには、次の手順を実行します。

Windows Server 2008

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] ウィンドウのツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、動的圧縮をインストールする場合は [動的なコンテンツの圧縮] を、静的圧縮をインストールする場合は [静的なコンテンツの圧縮] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーで [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. コントロール パネルで、[プログラムと機能][Windows の機能の有効化または無効化] の順にクリックします。

  3. [Internet Information Services][World Wide Web サービス][性能機能] の順に展開します。

  4. 動的圧縮をインストールする場合は [HTTP 動的圧縮] を、静的圧縮をインストールする場合は [静的なコンテンツの圧縮] を選択します。

    拡大

  5. [OK] をクリックします。

方法

サイトまたはアプリケーションで静的圧縮と動的圧縮を有効または無効にする方法

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、圧縮を有効にする接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで [圧縮] をダブルクリックします。

    拡大

  4. [圧縮] ウィンドウで、チェック ボックスをオンにして静的または動的圧縮を有効にするか、チェック ボックスをオフにして静的または動的圧縮を無効にします。

    拡大

  5. 上記の手順を完了したら、[操作] ウィンドウで [適用] をクリックします。

サーバーで静的圧縮と動的圧縮を有効または無効にする方法

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウでサーバーの名前を強調表示します。

  3. サーバーの [ホーム] ウィンドウで [圧縮] をダブルクリックします。

    拡大

  4. [圧縮] ウィンドウで、チェック ボックスをオンにして静的または動的圧縮を有効にするか、チェック ボックスをオフにして静的または動的圧縮を無効にします。

    拡大

  5. 上記の手順を完了したら、[操作] ウィンドウで [適用] をクリックします。

構成

属性

属性 説明
cacheControlHeader オプションの string 属性。

HTTP Expires ヘッダーを上書きする Cache-Control ヘッダーに IIS によって追加されるディレクティブを指定します。この属性により、古いクライアントとプロキシ サーバーが圧縮ファイルをキャッシュしなくなります。この設定を有効にするには、sendCacheHeaders 属性を true に設定する必要があります。このプロパティへの変更を有効にするには WWW サービスを再起動する必要があります。

既定値は max-age=86400 です。
directory オプションの string 属性。

静的ファイルの圧縮バージョンが一時的に格納およびキャッシュされるディレクトリを指定します。

: IIS 6.0 では、IIS 一時圧縮ファイルの既定のディレクトリ パスは、%windir%\IIS Temporary Compressed Files です。

既定値は %SystemDrive%\inetpub\temp\IIS Temporary Compressed Files です。
doDiskSpaceLimiting オプションの Boolean 属性。

directory 属性によって指定された圧縮ディレクトリに格納されている全圧縮ファイルが使用できるディスク容量を制限するかどうかを指定します。

既定値は true です。
dynamicCompressionDisableCpuUsage オプションの uint 属性。

動的圧縮が無効になる CPU 使用率 (パーセント) を指定します。

: この属性は、動的圧縮がオフになる CPU の上限として機能します。CPU 使用率が dynamicCompressionEnableCpuUsage 属性で指定した値を下回ると、動的圧縮が再び有効になります。

既定値は 90 です。
dynamicCompressionEnableCpuUsage オプションの uint 属性。

動的圧縮が有効になる CPU 使用率 (パーセント) を指定します。この値は 0 ~ 100 の間にする必要があります。平均の CPU 使用率は 30 秒ごとに計算されます。

: この属性は、動的圧縮がオンになる CPU の下限として機能します。CPU 使用率が dynamicCompressionDisableCpuUsage 属性で指定した値を上回ると、動的圧縮が無効になります。

既定値は 50 です。
expiresHeader オプションの string 属性。

cacheControlHeader 属性で指定した Cache-Control ヘッダーと共に、要求されたすべての圧縮ファイルと共に送信される HTTP Expires ヘッダーのコンテンツを指定します。このヘッダーの組み合わせにより、古いクライアントとプロキシ サーバーが圧縮ファイルをキャッシュしなくなります。この設定を有効にするには、sendCacheHeaders 属性を true に設定する必要があります。このプロパティへの変更を有効にするには World Wide Web 発行サービス (WWW サービス) を再起動する必要があります。

既定値は Wed, 01 Jan 1997 12:00:00 GMT です。
maxDiskSpaceUsage オプションの uint 属性。

圧縮ディレクトリに圧縮ファイルを格納できるディスク領域の上限メガバイト数を指定します。圧縮ファイルの使用領域がこの属性の値の 90% を超えると、使用率レベルが 90% に達するまで、最も過去に使用したファイルから削除されます。

: IIS 6.0 では、この制限がバイトで表示されていましたが、IIS 7.0 では、メガバイトで表示されています。IIS 7.0 では、この制限はアプリケーション プールごとに適用されます。

既定値は 100 です。
minFileSizeForComp オプションの uint 属性。

オンデマンド圧縮を使用するためにファイルが含む必要のある下限キロバイト数を指定します。

既定値は 256 です。
noCompressionForHttp10 オプションの Boolean 属性。

HTTP 1.0 バージョン番号を持つ要求に対して圧縮を無効にするかどうかを指定します。

: HTTP 1.0 クライアントの一部では、圧縮オブジェクトのキャッシュを正しく処理できません。この設定を使用すると、ファイルを解凍できないクライアントに圧縮ファイルを返すのを防ぐことができます。

既定値は true です。
noCompressionForProxies オプションの Boolean 属性。

プロキシ サーバー経由の圧縮要求に対して HTTP 1.1 応答を無効にするかどうかを指定します。

: HTTP 1.0 プロキシ サーバーの一部では、圧縮オブジェクトのキャッシュを正しく処理できません。この設定を使用すると、ファイルを解凍できないプロキシ サーバーに圧縮ファイルを返すのを防ぐことができます。

既定値は true です。
noCompressionForRange オプションの Boolean 属性。

Range ヘッダーを含む HTTP 要求に対して圧縮を無効にするかどうかを指定します。

: 一部のクライアントでは range 要求を正しく処理できません。この設定を使用すると、ファイルを解凍できないクライアントに圧縮ファイルを返すのを防ぐことができます。

既定値は true です。
sendCacheHeaders オプションの Boolean 属性。

cacheControlHeader および expiresHeader で構成されたヘッダーを各圧縮応答と共に送信するかどうかを指定します。

既定値は false です。
staticCompressionDisableCpuUsage オプションの uint 属性。

静的圧縮が無効になる CPU 使用率 (パーセント) を指定します。この値は 0 ~ 100 の間にする必要があります。平均の CPU 使用率は 30 秒ごとに計算されます。

: このプロパティは、静的圧縮がオフになる CPU の上限として機能します。CPU 使用率が staticCompressionEnableCpuUsage 属性で指定した値を下回ると、静的圧縮が再び有効になります。

既定値は 100 です。
staticCompressionEnableCpuUsage オプションの uint 属性。

静的圧縮が有効になる CPU 使用率 (パーセント) を指定します。この値は 0 ~ 100 の間にする必要があります。平均の CPU 使用率は 30 秒ごとに計算されます。

: このプロパティは、静的圧縮がオンになる CPU の下限として機能します。CPU 使用率が staticCompressionDisableCpuUsage 属性で指定した値を上回ると、静的圧縮が無効になります。

既定値は 50 です。

子要素

要素 説明
scheme オプションの要素。

IIS でクライアント要求を圧縮するために使用する圧縮方式 (Gzip または Deflate) を指定します。
dynamicTypes オプションの要素。

動的圧縮の構成設定を指定します。
staticTypes オプションの要素。

静的圧縮の構成設定を指定します。

構成サンプル

IIS 7.0 の ApplicationHost.config ファイルでは、次の既定の <httpCompression> 要素が構成されています。この構成セクションでは、<clear> 要素を使用している場合を除き、既定の構成設定を継承します。

<httpCompression
      directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
   <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
   <dynamicTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />

      <add mimeType="*/*" enabled="false" />
   </dynamicTypes>
   <staticTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />

      <add mimeType="*/*" enabled="false" />
   </staticTypes>
</httpCompression>

サンプル コード

次のコード サンプルでは、動的圧縮の種類の一覧に Office 2003 文書の MIME の種類を追加します。

( : Office 2007 文書では、組み込み圧縮機能を使用するため、文書を IIS で圧縮する必要はありません。)

AppCmd.exe

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/msword',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-powerpoint',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-excel',enabled='True']" /commit:apphost

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection httpCompressionSection = config.GetSection("system.webServer/httpCompression");
         ConfigurationElementCollection dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

         ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
         addElement["mimeType"] = @"application/msword";
         addElement["enabled"] = true;
         dynamicTypesCollection.Add(addElement);

         ConfigurationElement addElement1 = dynamicTypesCollection.CreateElement("add");
         addElement1["mimeType"] = @"application/vnd.ms-powerpoint";
         addElement1["enabled"] = true;
         dynamicTypesCollection.Add(addElement1);

         ConfigurationElement addElement2 = dynamicTypesCollection.CreateElement("add");
         addElement2["mimeType"] = @"application/vnd.ms-excel";
         addElement2["enabled"] = true;
         dynamicTypesCollection.Add(addElement2);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim httpCompressionSection As ConfigurationSection = config.GetSection("system.webServer/httpCompression")
      Dim dynamicTypesCollection As ConfigurationElementCollection = httpCompressionSection.GetCollection("dynamicTypes")

      Dim addElement As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement("mimeType") = "application/msword"
      addElement("enabled") = True
      dynamicTypesCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement1("mimeType") = "application/vnd.ms-powerpoint"
      addElement1("enabled") = True
      dynamicTypesCollection.Add(addElement1)

      Dim addElement2 As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement2("mimeType") = "application/vnd.ms-excel"
      addElement2("enabled") = True
      dynamicTypesCollection.Add(addElement2)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST");
var dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection;

var addElement = dynamicTypesCollection.CreateNewElement("add");
addElement.Properties.Item("mimeType").Value = "application/msword";
addElement.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement);

var addElement1 = dynamicTypesCollection.CreateNewElement("add");
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint";
addElement1.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement1);

var addElement2 = dynamicTypesCollection.CreateNewElement("add");
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel";
addElement2.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement2);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST")
Set dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection

Set addElement = dynamicTypesCollection.CreateNewElement("add")
addElement.Properties.Item("mimeType").Value = "application/msword"
addElement.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement)

Set addElement1 = dynamicTypesCollection.CreateNewElement("add")
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint"
addElement1.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement1)

Set addElement2 = dynamicTypesCollection.CreateNewElement("add")
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel"
addElement2.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement2)

adminManager.CommitChanges()

次のコード サンプルでは、静的圧縮の種類の一覧に Office 2003 文書の MIME の種類を追加します。

( : Office 2007 文書では、組み込み圧縮機能を使用するため、文書を IIS で圧縮する必要はありません。)

AppCmd.exe

appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/msword',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/vnd.ms-powerpoint',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/vnd.ms-excel',enabled='True']" /commit:apphost

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection httpCompressionSection = config.GetSection("system.webServer/httpCompression");
         ConfigurationElementCollection staticTypesCollection = httpCompressionSection.GetCollection("staticTypes");

         ConfigurationElement addElement = staticTypesCollection.CreateElement("add");
         addElement["mimeType"] = @"application/msword";
         addElement["enabled"] = true;
         staticTypesCollection.Add(addElement);

         ConfigurationElement addElement1 = staticTypesCollection.CreateElement("add");
         addElement1["mimeType"] = @"application/vnd.ms-powerpoint";
         addElement1["enabled"] = true;
         staticTypesCollection.Add(addElement1);

         ConfigurationElement addElement2 = staticTypesCollection.CreateElement("add");
         addElement2["mimeType"] = @"application/vnd.ms-excel";
         addElement2["enabled"] = true;
         staticTypesCollection.Add(addElement2);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim httpCompressionSection As ConfigurationSection = config.GetSection("system.webServer/httpCompression")
      Dim staticTypesCollection As ConfigurationElementCollection = httpCompressionSection.GetCollection("staticTypes")

      Dim addElement As ConfigurationElement = staticTypesCollection.CreateElement("add")
      addElement("mimeType") = "application/msword"
      addElement("enabled") = True
      staticTypesCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = staticTypesCollection.CreateElement("add")
      addElement1("mimeType") = "application/vnd.ms-powerpoint"
      addElement1("enabled") = True
      staticTypesCollection.Add(addElement1)

      Dim addElement2 As ConfigurationElement = staticTypesCollection.CreateElement("add")
      addElement2("mimeType") = "application/vnd.ms-excel"
      addElement2("enabled") = True
      staticTypesCollection.Add(addElement2)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST");
var staticTypesCollection = httpCompressionSection.ChildElements.Item("staticTypes").Collection;

var addElement = staticTypesCollection.CreateNewElement("add");
addElement.Properties.Item("mimeType").Value = "application/msword";
addElement.Properties.Item("enabled").Value = true;
staticTypesCollection.AddElement(addElement);

var addElement1 = staticTypesCollection.CreateNewElement("add");
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint";
addElement1.Properties.Item("enabled").Value = true;
staticTypesCollection.AddElement(addElement1);

var addElement2 = staticTypesCollection.CreateNewElement("add");
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel";
addElement2.Properties.Item("enabled").Value = true;
staticTypesCollection.AddElement(addElement2);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST")
Set staticTypesCollection = httpCompressionSection.ChildElements.Item("staticTypes").Collection

Set addElement = staticTypesCollection.CreateNewElement("add")
addElement.Properties.Item("mimeType").Value = "application/msword"
addElement.Properties.Item("enabled").Value = True
staticTypesCollection.AddElement(addElement)

Set addElement1 = staticTypesCollection.CreateNewElement("add")
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint"
addElement1.Properties.Item("enabled").Value = True
staticTypesCollection.AddElement(addElement1)

Set addElement2 = staticTypesCollection.CreateNewElement("add")
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel"
addElement2.Properties.Item("enabled").Value = True
staticTypesCollection.AddElement(addElement2)

adminManager.CommitChanges()