How to Prevent Chrome Browser from Caching 301 Redirects

Tadashi Shigeoka ·  Tue, September 24, 2019

I’ll introduce how to prevent Chrome browser from caching 301 redirects.

Google Chrome

Background of the 301 Redirect Cache Problem

The problem occurred in the shortened URL feature of a web service, following these steps:

  1. Create a shortened URL
  2. Open the shortened URL in Chrome browser
  3. Change the redirect destination URL of the shortened URL
  4. Open the shortened URL in Chrome browser again, but it redirects to the previous URL

How to Solve Only in Your Local Environment with Chrome Developer Tools

As described in the above articles, clear the browser cache.

How to Solve on the Shortened URL Service Side

Use 302 or 307 Instead of 301

If it meets your requirements, you can avoid browser cache by using 302 or 307 instead of 301.

301 is Still Cached Even with HTTP Header no-cache

For example, even if you specify HTTP headers like

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache

Chrome is designed to cache the browser response. The reason is as quoted below:

Note that HTTP 301 is Moved Permanently so caching the response is perfectly allowed. If you don't want the response to be cached, try 302 or 307. en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection - Wikipedia

Ref: web development - How can I make Chrome stop caching redirects? - Super User

301 Moved Permanently is an HTTP response status code that indicates a permanent redirect, so it’s not suitable for cases where the redirect destination may change. In such cases, you should use 302 Found or 307 Temporary Redirect, which indicate temporary changes.

That’s all from the Gemba.

Reference Information