当前位置: 代码迷 >> Web前端 >> HTTP header仅有cache validator 没cache(Expire/Cache Control)信息, 页面会被cache吗
  详细解决方案

HTTP header仅有cache validator 没cache(Expire/Cache Control)信息, 页面会被cache吗

热度:1046   发布时间:2013-12-15 22:17:18.0
HTTP header仅有cache validator 没有cache(Expire/Cache Control)信息, 页面会被cache吗?

?

HTTP header仅有cache validator没有cache(Expire/Cache Control)信息, 页面会被cache吗?
?

1. HTTP是通过Header Expire (HTTP1.0) 和 Cache Control (HTTP 1.0) 控制一个页面是否要被缓存.

?

  1. status:
    200 OK
  2. cache-control:
    public, max-age=31536000
  3. content-length:
    59173
  4. content-type:
    image/png
  5. date:
    Fri, 06 Dec 2013 00:07:14 GMT
  6. expires:
    Sat, 06 Dec 2014 00:07:14 GMT
  7. last-modified:
    Tue, 12 Nov 2013 01:05:01 GMT
  8. version:
    HTTP/1.1

在页面没有过期之前,所有的请求都会走缓存. 如果头部同时Expire?和Cache Control, 浏览器会用Cache Control覆盖Expire.

?

2. 如果Response没有任何缓存的信息(Expire和Cache Control)., 仅有cache validator(ast-modified/ETag)页面会走cache吗

?

下面的一段内容是从HTTP协议摘取过来的

?

13.4?Response Cacheability

Unless specifically constrained by a cache-control (section?14.9) directive, a caching system MAY always store a successful response (see section?13.8) as a cache entry, MAY return it without validation if it is fresh, and MAY return it after successful validation. If there is neither a cache validator nor an explicit expiration time associated with a response, we do not expect it to be cached, but certain caches MAY violate this expectation (for example, when little or no network connectivity is available). A client can usually detect that such a response was taken from a cache by comparing the Date header to the current time.

      Note: some HTTP/1.0 caches are known to violate this expectation
      without providing any Warning.

However, in some cases it might be inappropriate for a cache to retain an entity, or to return it in response to a subsequent request. This might be because absolute semantic transparency is deemed necessary by the service author, or because of security or privacy considerations. Certain cache-control directives are therefore provided so that the server can indicate that certain resource entities, or portions thereof, are not to be cached regardless of other considerations.

?

从红色字体中我们可以了解

1. 如果response头部既没有 cache validator (last-modified/ETag) 也没有 expiration time(Expires/Cache control), HTTP是不推荐缓存页面的.?

2. 如果response头部既有 cache validator?(last-modified/ETag),也有expiration time(Expires/Cache control),?页面也会被缓存住.?

3. 那如果response头部仅有?cache validator(last-modified/ETag) 了, 从文字上理解, 似乎页面要被缓存住的? ?通过在chrome和firefox上测试(请看附件).后面的请求的的确是走缓存的,?但是cache会存在多少时间了(没有地方显式设置时间呀)???

?

3. 思考

如果cache validator (last-modified/ETag) 脱离 cache?(Expire/Cache Control) 设置单独存在, 是个异常情况, 皮之不存,毛将焉附.

chrome/firefox在这种情况,还是会缓存页面的, 随后的请求也会走cache的.但是cache有效时间多少了?

?

?

?

Referrences:

  1. http://hmh1985.iteye.com/admin/blogs/1988105
  2. http://stackoverflow.com/questions/5860216/no-expires-header-sent-content-cached-how-long-until-browser-makes-conditional
  3. https://developers.google.com/speed/docs/best-practices/caching
  4. http://developer.yahoo.com/performance/rules.html?(Add an Expires or a Cache-Control Header)

?

?

  相关解决方案