【发布时间】:2012-09-29 00:45:26
【问题描述】:
在 IIS 7.5 中,我将 cacheControlMaxAge 设置为一年
<location path="Content/Images">
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
</system.webServer>
</location>
根据本指南:Setting Expires and Cache-Control: max-age headers for static resources in ASP.NET
但是,Google PageSpeed 工具仍然说文件没有被缓存:
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
* https://local.example.com/Content/Images/image1.png (expiration not specified)
(etc)
为什么会显示“未指定有效期”?
整个 webapp 都通过 https 提供服务,这是一个因素吗?
【问题讨论】:
-
您是否检查了 image1.png 的 http 标头?您可以在浏览器的开发工具(Chrome/FF/IE 中的 F12)中的网络选项卡下执行此操作。或者你可以使用提琴手。如果设置了最大年龄,所有现代浏览器都会通过 https 缓存项目。
-
http 标头说
Cache-Control: public,但没有提及到期,到期标头应该叫什么? -
已解决:将缓存属性添加到
location path="Content"而不是location path="Content/Images"解决了问题。 -
如果您已经解决了问题,您能否将答案发布为答案?
标签: asp.net-mvc caching https iis-7.5 browser-cache