As you most likely known since you found this post, Google Chrome - just like most other browsers - implements the 301 redirect caching, meaning that it will often locally cache the HTTP 301 redirects for a given amount of time without asking the server another HTTP response for that same URL.
This is a perfectly fine behaviour, as it's explicitly allowed by the RFC 7231 Section-6.4.2, which says the following:
A 301 response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls (see Section 4.2.2 of [RFC7234]).
The only downside of that is that, whenever you're testing or developing a web site (or a web server such as IIS or NGINX) and temporarily configure a HTTP 301 that you want to change later on, you could run into that redirect for a long period of time, thus being unable to access the previously-301 URL, page or resource.
In my specific case it happens all the time, to the point that I always work with my development browsers cache disabled: if I need to test stuff with a non-development browser, I'm often using the Incognito Mode, which flushes its cache everytime the browser is closed. However, such issue can often occur on a non-development browser as well, forcing you to take action in one of the following ways.
#1: Clear All the Browser's Cache Data
You can always fix this issue - together with all caching problems - by clearing all of your browser cache in the following way:
- Menu > Settings > Show advanced settings > Privacy, then click on Clear browsing data...
- Ensure that "Cached images and files" is a checked option (the rest is optional, depending on what you want to clear)
- Click the Clear browsing data button.
This will indeed fix your problem, yet it will also delete your cache data for any other site as well... kinda extreme, isn't it?
Luckily enough, there's a smarter thing you can do, although it requires a bit more work.
#2: Clear Cache Data for a specific URL
This neat method allows you to clear the Google Chrome's Cache Data for a specific URL. It can also be used with other browsers, such as Mozilla Firefox, IE and Edge, as long as they support the same features explained below.
- Press SHIFT+CTRL+I to open the Google Chrome Developer Tools panel.
- Go to the Network tab and select the Disable cache checkbox to enable that feature.
- Type the URL you want to clear from the browser cache in the address bar and press Enter.
- Click and hold the reload button until a modal window pops up, the select the Empty Cache and Hard Reload hidden option.
- As soon as the page has been fully reloaded, you can unselect the Disable cache checkbox and disable that feature.
It's worth noting that the Developer Tools panel must remain open for the whole process, otherwise Chrome won't let you to use Empty Cache and Hard Reload feature.
#3: Use the Chrome Incognito Mode
Alternatively, you can always use the Incognito Mode, which flushes its cache everytime the browser is closed. The only downside is that you won't fix your 301 caching issues in the "main" browser: if you want to do that as well, use the above options instead.
#4: Use the Chrome Fetch API
Here's a recent workaround that takes advantage to the Google Chrome fetch() API which has been discovered by one of our readers and definitely seems to work (thanks to Santiago for reporting it!):
- Go to www.google.com (or any other wesite with a non-restrictive CORS policy - read here if you don't know what we're talking about)
- Press SHIFT+CTRL+J to open the Google Chrome's console window.
- Write the following line:
1 |
fetch('https://www.example.com', {method: 'post'}).then(() => {}) |
Needless to say, you'll have to replace www.example.com with the actual URL that you want to remove from the cache.