How to detect when XHR returns a cached resource?

前端 未结 3 2081
难免孤独
难免孤独 2020-12-16 15:57

I\'m wondering if there is a way how to detect when a response is returned from a local cache? Is it possible?

The solution should be general and work for unconditi

3条回答
  •  抹茶落季
    2020-12-16 16:29

    The answer is Date header

    • If date header is before send date then a response is coming from a cache.
    • If date header is after date when a request was sent then a response is fresh.

    e.g.

    • from cache: request was sent at 11:00, response date is 10:59
    • no cache: request was sent at 11:00, response date is 11:01

提交回复
热议问题