启用 IIS7 gzip [英] Enable IIS7 gzip

查看:24
本文介绍了启用 IIS7 gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启用 IIS7 对 js 和 css 等静态文件进行 gzip,以及如何在发送到客户端之前测试 IIS7 是否真的对它们进行了 gzip?

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?

推荐答案

配置

您可以完全在 Web.config 文件中启用 GZIP 压缩.如果您使用的是共享主机并且无法直接配置 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	empIIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%system32inetsrvgzip.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆