在 YSlow 的帮助下,我正在尝试稍微调整我的页面。
我认为压缩我的页面会不费吹灰之力就能获得大 yield 。
在尝试了 here 中的所有内容之后, here , here和 here YSlow 仍然显示我的页面未压缩。
我在 IIS6 上使用 asp.net mvc 1.0。
通过我的 global.asax 中的以下规则,我确保我的静态内容不由 MVC 处理。
routes.Clear();
// Turns off the unnecessary file exists check
routes.RouteExistingFiles = true;
// Ignore text, html, files.
routes.IgnoreRoute("{file}.txt");
routes.IgnoreRoute("{file}.htm");
routes.IgnoreRoute("{file}.html");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Ignore the content directory which contains images, js, css & html
routes.IgnoreRoute("Content/{*pathInfo}");
//Exclude favicon (google toolbar request gif file as fav icon which is weird)
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });
这将确保我的 js 和 css 文件可以静态访问。
这些是我的metabase.xml的相关片段
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="0"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
css
js
mvc"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe"
>
</IIsCompressionScheme>
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
css
js
mvc"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe"
>
</IIsCompressionScheme>
(元:不确定我应该把它放在 SO 还是 SF 上)
最佳答案
问题是压缩与扩展相关,您需要指定应获得静态或动态压缩的所有扩展。您可以通过分别查看 HcFileExtensions 和 HcScriptFileExtensions 属性来看到这一点。
因此,随着 MVC 硬塞到 IIS6 中,您不一定有文件扩展名,因此您将无法对动态内容进行任何压缩。 IIS7 的做法有所不同,因为它使用 mimeType 列表来触发压缩。具有集成管道的 IIS7 是我们真正期望放置 MVC 应用程序的地方。在 IIS6 中这是可能的,但它是一种拼凑,而压缩是受害者之一。
编辑
对于 IIS6 上的静态内容,请记住,压缩发生在单独的线程上,并在第一次请求资源后触发,第一个请求本身未压缩。随后应使用压缩版本提供对该资源的后续请求。
关于asp.net-mvc - 为什么我的页面仍未被 gzip 压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/999984/