IIS 7.5 不一致的 Gzips 文件(使用 PHP 和 ASP.NET)

ada*_*sdf 4 compression asp.net gzip iis-7.5

我对web.config运行 IIS 7.5 的服务器进行了一些更改,以提高性能(主要是前端)。

第三方测试工具说该站点运行的是“PHP/5.3.10, ASP.NET”,如果没记错的话,它是 ASP.NET 4.5

我认为这是由于奇怪的技术组合(例如在 IIS 上运行 PHP),但接触任何东西都会让我感到紧张。

我从H5BP IIS 服务器配置中添加了(仅)过期标头和 gzip 的指令

我想我在 2013 年 1 月 15 日下午添加了这些指令。 Pingdom 性能测试工具中的站点测试历史记录可在此处获得

您可以看到传输大小急剧下降的地方(单击历史记录选项卡)。

从那时起,似乎每次我测试它时,不同的文件(通常是 CSS 和 JS 之类的资产)都或不与 gzip 一起提供,没有押韵或原因。有时似乎所有东西都用 gzip 提供,有时似乎几乎没有任何东西被压缩,但它通常在中间的某个地方(正如你在历史中看到的那样)。

到底是怎么回事?

我该如何解决?

这个网站没有在积极开发中,虽然在 15 日之后页面中添加了一些额外的数据(我添加了 Google Analytics 插件脚本以改进跟踪),但没有什么可以解释如此大的变化和不一致。

我最好的猜测是它与用于压缩的 CPU 资源有关,这个问题似乎很接近:为什么 gzip 压缩在 IIS 中的效率不同?

agr*_*ath 7

我在本页的评论中发现了一个可能的罪魁祸首; weblog.west-wind.com

本质上,OOTB、IIS 只会在 10 秒内至少请求文件两次时进行 gzip。

这是通过 web.config 调整的 - 不幸的是,默认情况下它是锁定的,因此您必须编辑 applicationhost.config 以将 overrideModeDefault="DENY" 更改为 ALLOW。

参考在这里:forums.iis.net

相关配置片段如下。你会看到我也弄乱了 SVG 字体的内容类型,因为默认情况下 IIS 不会对它们进行 gzip,因此通过强制它们为 text/xml,它们也会被压缩。(谷歌 PageSpeed对此有抱怨)

网页配置

  <system.webServer>
        <serverRuntime frequentHitThreshold="1" enabled="true" />
        <staticContent>
              <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
              <remove fileExtension=".svg" />
              <mimeMap fileExtension=".svg" mimeType="text/xml" />
        </staticContent>
        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
            <dynamicTypes>
                <add mimeType="*/*" enabled="true" />
            </dynamicTypes>
            <staticTypes>
                <add mimeType="image/svg+xml" enabled="true" />
                <add mimeType="text/xml" enabled="true" />
                <add mimeType="*/*" enabled="true" />
            </staticTypes>
        </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
    </system.webServer>
Run Code Online (Sandbox Code Playgroud)

应用程序主机配置文件

      <section name="serverRuntime" overrideModeDefault="Allow" />
Run Code Online (Sandbox Code Playgroud)