根据 Firebug 的说法,静态文件仅在 Fiddler 运行时才会被压缩 - 为什么?
我有一个在 IIS 6.0 中运行的 ASP.NET MVC 站点,并希望它压缩它所提供的静态 css 和 js 文件。该站点具有通配符映射,因此所有请求(包括无扩展名的 URL)都通过 aspnet_isapi.dll 进行。静态内容保存在 Content 和 Scripts 文件夹中。
我已执行以下步骤:
在 IIS 控制台(“网站 -> 服务”选项卡)中为应用程序文件和静态文件启用 HTTP 压缩。
添加了一个名为“HTTP Compression”的 Web 服务扩展,引用了 inetsrv\gzip.dll
编辑了 MetaBase.xml 以添加将 css 和 js 添加到 gzip 的 HcFileExtensions 属性并缩小 IIsCompressionScheme 条目。
从内容和脚本文件夹中删除了通配符映射(通过暂时将它们设为子网站、删除通配符映射、将它们恢复为普通文件夹来实现)。这应该确保 IIS 在不涉及 ASP.NET 的情况下提供这些文件。
我现在得到的奇怪行为是,当 Fiddler 运行时,它报告 css 和 js 的压缩文件大小,Firebug 也同意(例如 jquery-ui.min.js 为 47.9KB)。但是,当我禁用 Fiddler 并按 CTRL+F5 时,Firebug 会报告未压缩的大小(jquery-ui.min.js 为 194.2KB)以及意外的 Content-Type 和 Content-Length。
请求标头不会改变,但查看响应标头很有趣。 当 Fiddler 运行时,Firebug 报告(对于 jquery-ui.min.js):
Content-Length 49009
Content-Type application/x-javascript
Content-Encoding gzip
Last-Modified Wed, 26 Jan 2011 11:59:25 GMT
Accept-Ranges bytes
Etag "80cce07950bdcb1:a03"
Vary Accept-Encoding
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
x-ua-compatible IE=8
没有 Fiddler:
Proxy-Authenticate NTLM
Content-Length 415
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=iso-8859-1
为什么 Content-Type 现在是 text/html? 415 的 Content-Length 看起来很奇怪,它与 Firebug 报告的响应大小 194.2KB 不匹配。各种其他标头不再存在。
为了完整起见,请求标头为:
Host my-windows-box
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0E)
Accept */*
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Proxy-Connection keep-alive
Referer http://my-windows-box/site
Cookie ASP.NET_SessionId=nbsb2hbkjdtcgjdntco25zqc
Pragma no-cache
Cache-Control no-cache
I have an ASP.NET MVC site running in IIS 6.0 and want it to compress the static css and js files it serves. The site has a wildcard mapping so all requests (inc. extensionless URLs) go via aspnet_isapi.dll. Static content is held in the Content and Scripts folders.
I have carried out the following steps:
Enabled HTTP compression for application files and static files in the IIS Console (Web Sites -> Service tab).
Added a Web Service Extension named "HTTP Compression" referring to inetsrv\gzip.dll
Edited MetaBase.xml to add css and js to the HcFileExtensions property of the gzip and deflate IIsCompressionScheme entries.
Removed the wildcard mapping from the Content and Scripts folders (did so by temporarily making them subwebs, removed the wildcard map, reverted them back to ordinary folders). This should ensure IIS serves those files without ASP.NET getting involved.
The strange behaviour I now get is that, when Fiddler is running, it reports compressed file sizes for css and js, and Firebug concurs (e.g. 47.9KB for jquery-ui.min.js). But when I disable Fiddler and hit CTRL+F5, Firebug reports uncompressed sizes (194.2KB for jquery-ui.min.js) and unexpected Content-Type and Content-Length.
The request headers do not change, but it's interesting to look at the response headers.
With Fiddler running, Firebug reports (for jquery-ui.min.js):
Content-Length 49009
Content-Type application/x-javascript
Content-Encoding gzip
Last-Modified Wed, 26 Jan 2011 11:59:25 GMT
Accept-Ranges bytes
Etag "80cce07950bdcb1:a03"
Vary Accept-Encoding
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
x-ua-compatible IE=8
Without Fiddler:
Proxy-Authenticate NTLM
Content-Length 415
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=iso-8859-1
Why is Content-Type now text/html? The Content-Length of 415 looks odd, it doesn't match the 194.2KB that Firebug reports as the size of the response. Various other headers are no longer present.
For completeness, the request header is:
Host my-windows-box
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0E)
Accept */*
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Proxy-Connection keep-alive
Referer http://my-windows-box/site
Cookie ASP.NET_SessionId=nbsb2hbkjdtcgjdntco25zqc
Pragma no-cache
Cache-Control no-cache
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Firebug 中响应的状态代码是什么?我的第一个猜测是它是 HTTP/401,您在这里看到的是请求 NTLM 凭据的身份验证页面。
What's the status code on the response in Firebug? My first guess is that it's a HTTP/401 and what you're seeing here is the authentication page that requests your NTLM credentials.