启用IIS7 gzip [英] Enable IIS7 gzip
问题描述
如何启用IIS7 gzip静态文件像js和css如何测试IIS7是否真的gziping他们发送到客户端之前?
How can I enable IIS7 to gzip static files like js and css and how can I test if IIS7 is really gziping them before sending to the client?
谢谢!
推荐答案
配置
code> Web.config 文件。如果您使用的是共享主机,并且无法直接配置IIS,或者希望您的配置在您定位的所有环境之间传输,则这将非常有用。
Configuration
You can enable GZIP compression entirely in your Web.config
file. This is particularly useful if you're on shared hosting and can't configure IIS directly, or you want your config to carry between all environments you target.
<system.webServer>
<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>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
测试
工作与否,请使用 Chrome开发人员工具或 Firebug for Firefox ,并确保设置了HTTP响应标头:
Testing
To test whether compression is working or not, use the developer tools in Chrome or Firebug for Firefox and ensure the HTTP response header is set:
Content-Encoding: gzip
请注意,如果响应代码为304(未修改),则此标题将不存在。如果是这种情况,请进行完全刷新(按住刷新按钮时按住shift或control键),然后再次检查。
Note that this header won't be present if the response code is 304 (Not Modified). If that's the case, do a full refresh (hold shift or control while you press the refresh button) and check again.
这篇关于启用IIS7 gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!