How long do browsers cache HTTP 301s?

前端 未结 15 2448
囚心锁ツ
囚心锁ツ 2020-11-22 14:43

I am debugging a problem with a HTTP 301 Permanent Redirect. After a quick test, it seems that Safari clears its cache of 301s when it is restarted, but Firefox does not.

15条回答
  •  广开言路
    2020-11-22 15:11

    301 is a cacheable response per HTTP RFC and browsers will cache it depending on the HTTP caching headers you have on the response. Use FireBug or Charles to examine response headers to know the exact duration the response will be cached for.

    If you would like to control the caching duration, you can use the the HTTP response headers Cache-Control and Expires to do the same. Alternatively, if you don't want to cache the 301 response at all, use the following headers.

    Cache-Control: no-store, no-cache, must-revalidate
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    

提交回复
热议问题