【问题标题】:how to enabled gzip in asp.net?如何在 asp.net 中启用 gzip?
【发布时间】:2013-09-19 10:05:23
【问题描述】:

我想要网站中的 gzip css 和 js 文件。并在 web.config 中使用此代码:

<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"/>

使用 gtmetrix.com 网站分析我的网站,但得到:

Compressing the following resources with gzip could reduce their transfer size by 63.4KiB (77% reduction).

Compressing http://mysite.com/ could save 30.6KiB (74% reduction).
Compressing http://mysite.com/WebResource.axd?d=TdZvTxV1RZCMol6igoEA7XxfdqcWpTRlYuCxfymg_ruU4xc1NuSqLn7bduKh3WyPwSYX0g86d6fEJ3SVBdeWi5FBnMpKfcO7aaFoqvmTo_c1&t=634970873020000000 could save 17.5KiB (80% reduction).
Compressing http://mysite.com/main.css could save 14.8KiB (80% reduction).

【问题讨论】:

    标签: asp.net web-config gzip


    【解决方案1】:

    根据this answer,压缩发生在不同线程的后台进程中,因此在第一次请求时将不可用。另外,请记住,这不是 ASP.NET 功能,而是 IIS 功能。

    还有一个答案here 显示了有效的配置。

    提示:您可能还想使用bundling and minification 进行检查。

    【讨论】:

      【解决方案2】:

      对于您的网络配置中的动态类型,您还需要在 IIS 中安装动态压缩模块,否则这些将无济于事。

      【讨论】:

        【解决方案3】:

        我在文件管理器的 web.config 文件中找到了你应该使用的代码:

        <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>
        

        我现在在我的网站上使用它:www.irpolymer.com 但在 gtmetrix 中显示我的 gzip 已禁用,我认为它明天会修复。

        【讨论】:

          猜你喜欢
          • 2011-06-10
          • 1970-01-01
          • 2010-12-26
          • 1970-01-01
          • 2015-02-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多