douju6651 2015-02-01 12:40
浏览 65

没有“过期”和没有“缓存控制”标头集,但“最后修改”或“ETag”被忽略,为什么?

Chrome still loads the files from cache although the "ETag" changed and the "Last-Modified" is set to a newer date than the cached resource by the server. Why is that??

  • 写回答

1条回答 默认 最新

  • dsaf32131 2015-02-03 10:53
    关注

    It's good practice to always set Expires or the max-age in Cache-Control. If you don't specify when the resource expires browsers are allowed to use their own heuristic for caching. See section 13.2.4 of RFC 2616:

    If none of Expires, Cache-Control: max-age, or Cache-Control: s- maxage (see section 14.9.3) appears in the response, and the response does not include other restrictions on caching, the cache MAY compute a freshness lifetime using a heuristic. The cache MUST attach Warning 113 to any response whose age is more than 24 hours if such warning has not already been added.

    Also, if the response does have a Last-Modified time, the heuristic expiration value SHOULD be no more than some fraction of the interval since that time. A typical setting of this fraction might be 10%.

    The calculation to determine if a response has expired is quite simple:

      response_is_fresh = (freshness_lifetime > current_age)
    

    Chrome has cached the resource because you haven't indicated whether it should be cached or not. Last-Modified is only used by the browser to verify a resource once the browser has determined that it might be stale.

    You'll need to set Expires or Cache-Control to get the caching behaviour that you require.

    BTW, for most web sites a good rule of thumb is to expire HTML immediately but cache images, CSS and JavaScript forever:

    http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度