200 OK (from cache) 与 304 Not Modified

解释:

200 OK (from cache)  是浏览器没有跟服务器确认,直接用了浏览器缓存;

304 Not Modified 是浏览器和服务器多确认了一次缓存有效性,再用的缓存。

 

触发区别:

200 OK (from cache) 是直接点击链接访问,输入网址按回车访问也能触发;而 304 Not Modified 是刷新页面时触发,或是设置了长缓存、但 Entity Tags 没有移除时触发

 

Last-Modified这个头标是一个响应头标,表示客户端(通常指浏览器)所请求资源在服务器端的最后修改时间。通常情况下客户端在接受这个头标后,在以后对这个资源的请求会附带一个’If-Modified-Since’请求头标,而这个头标是想告诉服务器上次客户端所请求资源的最后修改时间。If-Modified-since 后面的内容是向服务器确认浏览器缓存中的内容是否过时。如果不过时,返回的就是304 Not Modified。

 

200 ok from cache 是通过Expires 和 Cache-Control: max-age来比较的。如果你触发一条新的请求的时候,这些缓存对象仍然存储在本地缓存并且尚未过期

If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.

如果您的服务器是Apache使用ExpiresDefault指令设置一个相对于当前日期截止日期。这个例子ExpiresDefault指令 设置请求时间 10年到期。

ExpiresDefault "access plus 10 years"

 

雅虎网页优化建议:https://developer.yahoo.com/performance/rules.html

posted @ 2016-05-31 00:17  小彭博客  阅读(2362)  评论(0编辑  收藏  举报