【问题标题】:Mvc 4 script bundles and GZipMvc 4 脚本包和 GZip
【发布时间】:2013-01-07 21:19:41
【问题描述】:

我已将我网站上的所有脚本添加到非常大的包中(大约 700kb)。现在我希望 IIS 对其进行 gzip,但我不能。

我已经尝试了在这里和网络上找到的所有内容,但没有任何帮助。静态 *.js 文件会被 gzip 压缩,但完整的捆绑包不会。

有什么解决办法吗?

【问题讨论】:

    标签: asp.net-mvc iis gzip bundle


    【解决方案1】:

    检查 IIS 中的dynamic compression。必须为 IIS 和您的网站启用它。您还必须在 applicationHost.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/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>
    

    重要提示:捆绑响应的内容类型为text/javascript,因此请检查您的配置是否为该类型。

    【讨论】:

    • 正如其他人所说,尽量不要使用notepad++或notepad,而是使用appcmd.exe来编辑applicationHost文件,这条命令帮助我编辑了文件:appcmd.exe set config -section:system。 webServer/httpCompression /+"dynamicTypes.[mimeType='application/javascript', enabled='True']" /commit:apphost
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多