2013-01-07 34 views
5

我已将我网站上的所有脚本添加到非常大的包(大约700kb)中。现在我希望IIS能够压缩它,但是我不能。Mvc 4脚本包和GZip

我试过了我在这里和网上找到的所有东西,但没有任何帮助。静态* .js文件年龄压缩,但完整的捆绑没有。

有没有解决方法?

回答

5

检查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,所以检查你的配置这种类型。

+0

正如其他人所说,尽量不要使用记事本++或记事本,但appcmd.exe编辑applicationHost文件这个单一的命令帮助我编辑文件:appcmd.exe set config -section:system.webServer/httpCompression/+ “dynamicTypes。[mimeType ='application/javascript',enabled ='True']”/ commit:apphost –