我试图通过设置web.config文件让YSlow在"Add Expires header"部分给我一个A.
我一直在环顾四周,这就是我根据那里的东西放入的东西:
<staticContent>
<clientCache httpExpires="15.00:00:00" cacheControlMode="UseExpires"/>
</staticContent>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
这就是我在Firebug中看到的:
Response Headers
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Sun, 28 Aug 2011 13:54:50 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: image/jpeg
Content-Length: 24255
Connection: Close
Request Headersview source
Host localhost:50715
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0
Accept image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Referer http://localhost:50715/MySite/SiteHome.html
Pragma no-cache
Cache-Control no-cache
Run Code Online (Sandbox Code Playgroud)
然而,当我在Firefox中看到它时,即使在Crtl-F5之后,Yslow仍在给出F值
我错过了什么?
谢谢.
mar*_*rkd 32
从.NET Daily,我成功地将其应用于IIS上的PHP站点.它将最大年龄设置为30天,而不必指定明确的日期.
将其添加到您的web.config文件中:
<system.webServer>
<staticContent>
<clientCache cacheControlMaxAge="30.00:00:00" cacheControlMode="UseMaxAge"/>
</staticContent>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
此配置满足PageSpeed"Leverage浏览器缓存"和YSlow"Add Expires headers".YSlow需要大于7天的值.PageSpeed需要30天到1年.
mag*_*tic 16
httpExpires属性的值必须是完全格式化的日期和时间,遵循RFC 1123中的规范.例如:Fri,01 Jan 2010 12:00:00 GMT
因此,如果要对静态内容使用http expires标头,请将其设置为:
<staticContent>
<clientCache cacheControlMode="UseExpires" httpExpires="Sun, 1 Jan 2017 00:00:00 UTC" />
</staticContent>
Run Code Online (Sandbox Code Playgroud)
更新(上面的评论):这很可能仍然无法在内置的VS服务器中运行.我不确定它是否支持过期标题.AFAIK这是一个IIS设置.