Mvc 4脚本捆绑和GZip

5

我已将我的网站所有脚本合并成一个很大的包(约700kb)。现在我想让IIS进行gzip压缩,但我做不到。

我尝试了这里和互联网上找到的所有方法,但都没有帮助。静态的*.js文件能被gzip压缩,但整个包却不能。

是否有任何解决方案?

1个回答

5

查看IIS中的动态压缩设置。需要在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,请检查您的配置是否正确。


就像其他人所说的那样,尽量不要使用记事本++或者记事本来编辑applicationHost文件,而是使用appcmd.exe命令来编辑。下面这个单一的命令可以帮助你编辑文件:appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/javascript', enabled='True']" /commit:apphost - Raphael Isidro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接