【问题标题】:How to Configure GZIP in IIS server?如何在 IIS 服务器中配置 GZIP?
【发布时间】:2015-05-26 10:29:43
【问题描述】:

我们使用 IIS 服务器,当我检查页面速度时,它告诉我压缩 m.domainname.com(移动域)中的 js 和 css 文件。不是说要压缩主域中的文件。

我尝试将此代码添加到 m.domainname.com 中的 web.config 中。

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/json" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/atom+xml" enabled="true" />
            <add mimeType="application/xaml+xml" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>

    <urlCompression doStaticCompression="true" doDynamicCompression="true" />

我没有看到任何效果。请帮忙。

【问题讨论】:

  • IIRC 您需要在 Windows 中安装一项功能以启用压缩。
  • IIRC -&gt; If I Recall Correctly。在“向 Windows 添加功能”对话框中查看您使用的任何 Windows 版本。
  • 如果我之前没有安装该功能,页面速度测试会要求我从主站点压缩我的 js 和 css 文件。但它没有。猜猜我已经安装了该功能。问题仅来自移动域。

标签: iis compression gzip


【解决方案1】:

通过 ASP.Net 内核提供压缩文件时,需要使用 CompressedStaticFiles 中间件。确保您的构建包含法线文件及其压缩版本,以使上述中间件能够正常工作。

Startup.Configure() 中放置app.UseCompressedStaticFiles(); 而不是app.UseStaticFiles();

这将确保您的应用程序在浏览器支持的情况下提供预压缩的 gzipped 和 brotli 压缩文件。

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多