如何检测,当XHR返回缓存的资源? [英] How to detect when XHR returns a cached resource?
本文介绍了如何检测,当XHR返回缓存的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道是否有一种方法如何检测时的响应从本地缓存返回?可能吗?
I'm wondering if there is a way how to detect when a response is returned from a local cache? Is it possible?
该解决方案应该是全面和无条件的要求工作。在这种情况下,响应code是总是200行,但XHR返回一个高速缓存资源的第二请求(例如,第一响应包含Expires头,所以没有必要请求服务器的新资源期满之前日期)。
The solution should be general and work for unconditional requests. In this case, the response code is always 200 OK, but XHR returns a cached resource for the second request (e.g. the first response contains Expires header, so there is no need to ask a server for a new resource before the expiration date).
推荐答案
答案是日期标题
- 如果日期头前,发送日期则响应从缓存来了。
- 如果日期标题为日后发送请求时,则反应是新鲜的。
例如。
- 从缓存:请求被发送时间为11:00,响应时间为10:59
- 没有缓存:请求已发送时间为11:00,响应时间为11:01
这篇关于如何检测,当XHR返回缓存的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文