How long do browsers cache HTTP 301s?

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.

When do IE, Chrome, Firefox and Safari clear their cache of 301s?

UPDATE: For example, if I want to redirect example1.com to example2.com, but I accidentally set it to redirect to example3.com, that is a problem. I can correct the mistake, but anyone who has visited example1.com in the meantime will have cached the incorrect redirect to example3.com, and so they will not be able to reach either example1.com or example2.com until their cache is cleared. Upon investigation, I find that there were no Cache-Control and Expires headers set. The headers for the incorrect 301 response would have been like this:

HTTP/1.1 301 Moved Permanently
Date: Wed, 27 Feb 2013 12:05:53 GMT
Server: Apache/2.2.21 (Unix) DAV/2 PHP/5.3.8
X-Powered-By: PHP/5.3.8
Location: http://example3.com/
Content-Type: text/html

My own tests show that:

  • IE7, IE8, Android 2.3.4 do not cache at all.
  • Firefox 18.0.2, Safari 5.1.7 (on Windows 7), and Opera 12.14 all cache, and clear the cache on browser restart.
  • IE10 and Chrome 25 cache, but do not clear on browser restart, so when will they clear?

17 Answers
17

An answer that helps those who desperately want to get rid of the redirect cache:

Chrome caches the 301 redirect infinitely (in the local disk cache). To clear this cache:

  • open your DevTools (press F12)
  • on the Network tab check the “Disable cache” checkbox
  • keep DevTools open and reload the page (press F5)

When everything is okay, you can uncheck “Disable cache” and everything will continue to work as expected.

Leave a Comment