啟用 HTTP 壓縮 (Gzip/Deflate) 是 YSlow/PageSpeed 關鍵優化項目,可**立竿見影減少 60-80% 文字內容傳輸量**,顯著提升頁面載入速度。
Accept-Encoding: gzip, deflate 表示支援壓縮
HcFileExtensions 屬性 (預設 htm, html, txt, css, js 等)HcScriptFileExtensions 屬性 (預設 aspx, ashx, asmx 等)C:\Windows\System32\inetsrv\MetaBase.xml (備份後修改)<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<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="application/javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
</system.webServer>
Content-Encoding: gzip| 優點 | 成本 |
|---|---|
| 傳輸量減少 60-80% | CPU 使用率略增 (現代 CPU 可忽略) |
HTTP 壓縮是投資報酬率最高的前端優化手段之一,建議所有生產環境啟用。