Understand If-Modified-Since HTTP Header

空扰寡人 提交于 2019-11-28 23:26:46
BalusC

A request with If-Modified-Since only makes sense if the client already has a resource which is obtained along with a response that has a Last-Modified header in combination with headers which allow browser caching like a Cache-Control and/or Pragma value containing public.

Also, I've noticed that some browsers does not include If-Modified-Since when the original response also contained an ETag header. The browser will instead use If-None-Match to test it.

See also:

alienhard

First you have to make sure the initial response is cached in the first place (I answered this in another, related question.

Try to set the following fields:

Last-Modified: Wed, 16 Feb 2011 13:52:26 GMT
Expires: -1
Cache-Control: must-revalidate, private
  • Last-Modified is needed as a validator (do not send ETag if you want to test for If-Modified-Since)
  • Expires -1 tells that the resource is stale and must always be revalidated
  • Cache-Control must not include no-cache nor no-store

When you send these headers on the initial HTTP/200 response, on subsequent requests, the browser should send conditional requests that include the If-Modified-Since header.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!