为什么我的页面仍未被 gzip 压缩?

发布于 2024-07-25 05:59:23 字数 2496 浏览 3 评论 0原文

在 YSlow 的帮助下,我正在尝试稍微调整我的页面。
我认为压缩我的页面会不费吹灰之力就能获得大收益。 在尝试了此处中的所有内容后,此处此处这里 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 上)

With the help of YSlow I'm trying to tune my pages a bit.
I thought it would be little effort for big gain to have my pages compressed.
After trying everything from here, here, here and here YSlow is still showing my pages are nog compressed.

I'm using asp.net mvc 1.0 on IIS6.

With the following rules in my global.asax I make sure that my static content is not handled by 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])(/.*)?" });

This will make sure that my js and css files are statically accessible.

These are the relevant snips of my 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>

(meta: not sure if I should be putting this on SO or on SF)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似最初 2024-08-01 05:59:23

问题是压缩与扩展相关,您需要指定应获得静态或动态压缩的所有扩展。 您可以通过分别查看 HcFileExtensions 和 HcScriptFileExtensions 属性来看到这一点。

因此,随着 MVC 硬塞进 IIS6,您不一定有文件扩展名,您将无法获得动态内容的任何压缩。 IIS7 的做法有所不同,因为它使用 mimeType 列表来触发压缩。 具有集成管道的 IIS7 是我们真正期望放置 MVC 应用程序的地方。 在 IIS6 中这是可能的,但它是一种拼凑,压缩是受害者之一。

编辑

对于 IIS6 上的静态内容,请记住,压缩发生在单独的线程上,并在第一个资源请求后触发,第一个请求本身未压缩。 随后应使用压缩版本提供对该资源的后续请求。

The problem is that compression is extension related, you need to specify all the extensions that should get either static or dynamic compression. You can probably see this by looking at the HcFileExtensions and HcScriptFileExtensions attributes respectively.

So with MVC shoe-horned into IIS6 where you don't necessarily have file extensions you will not be getting any compression for dynamic content. IIS7 does things differently since it uses a list of mimeTypes to trigger compression. IIS7 with integrated pipeline is where we're really expect to be placing MVC apps. In IIS6 its possible but its a kludge and compression is one of the casualties.

Edit

For static content on IIS6 bear in mind that compression happens on a separate thread and triggered after the first request to resource, the first request itself goes out uncompressed. Subsequent requests for the resource should then be supplied using the compressed version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文