97

Is there any way to disable this 'feature'?

For example, if a request is made to http://localhost/foo.html that I have specified to '301' to the root address, all subsequent requests to foo.html bypass the web server completely and ffox 5 will check it's cache, read that this url was '301'ed previously and redirect without even checking for a change.

If i have stopped foo.html from 301'ing, I have to clear firefox's cache in order to 'fix' this from happening.

Chrome, IE and previous version of Firefox do not do this.

Charles
  • 50,943
  • 13
  • 104
  • 142
maxp
  • 24,209
  • 39
  • 123
  • 201
  • Even deleting the cache doesn't resolve this error for me (Firefox 17.0.1, Linux). – Konrad Höffner Dec 10 '12 at 09:58
  • 2
    @kirdie In the "clear recent history" dialog, make sure you set the time range to "everything", and check the "cache" checkbox. If the time range selected is more recent than your visits to the redirected url, the cache entry won't be cleared. – Kelvin Jan 09 '13 at 21:11
  • 13
    @kirdie and everybody with the same problem: Look at the history with Ctrl + H. Then right click the site and choose "delete all history for this site" (or something similar). That did it for me. – Lars Nyström Mar 25 '13 at 12:54
  • 4
    @LarsNyström: Developing a web app and ran into this - your suggestion worked flawlessly for me. It was "Forget about this site" in FF20.0 – cincodenada Aug 09 '13 at 23:11
  • 1
    Isn't 301 called "moved **permanently**" If I have a server serving only https and people go to my domain name using http (bad enough as it is, because they'll reveal the request uri), I would like the browser to remember that **permanently** and not check http every time. –  Apr 27 '14 at 22:31
  • if you are stuck with a malicious ISP who intercepts your requests and redirects them, then you want a way to disable permanent redirects. – eMBee Sep 02 '15 at 19:41
  • In my case, loading *http://www.example.com/?* instead of *http://www.example.com/* worked around the problem : the web server was contacted again for that specific query, but *http://www.example.com/* remained cached as moved permanently. – YoungFrog Nov 29 '16 at 09:43
  • @eMBee How about a way to disable the permanence of them? It would be far less disruptive than disabling such redirects altogether. – Stewart Dec 19 '21 at 22:51

9 Answers9

135

In Firefox you have the "Web Developer" Tools (Ctrl+Shift+I). You can click "Network" tab and check the checkbox "Disable Cache" to check for new version of page every time. Then load the original URL and it will refresh your cache. Then you can enable the cache again and access that URL also from other tabs. So you don't need to clear your full cache.


From cptstubing06's comment, the following can help clear the cache:

  1. Type Ctrl+l to put the cursor on the location bar.
  2. Type about:config to open the configuration settings.
  3. Confirm any warnings.
  4. Type browser.cache followed by Enter to filter the settings.
  5. Double-click browser.cache.check_doc_frequency.
  6. Change the value from 3 to 1.
  7. Click OK.
  8. Revisit the obsessively cached 301 page.
  9. Reset the frequency back to 3 when finished.

Firefox should now redirect to the new 301 page, no longer fetching the redirected page from cache.

hynekcer
  • 14,942
  • 6
  • 61
  • 99
Steve Parish
  • 1,824
  • 2
  • 14
  • 12
  • 5
    This is a great solution for me -- I *want* a cached 301 99% of the time, but once in a blue I might need to change the location of the redirect, and don't want to clear my ENTIRE cache. Just to clarify, Firefox comes with its own `Web Developer` menu under tools, which is not the addon. The addon is also called `Web Developer`, but shows up in your Tools menu as `Web Developer Extension` and can be downloaded here: https://addons.mozilla.org/en-us/firefox/addon/web-developer/ . – cptstubing06 Feb 03 '13 at 16:22
  • 5
    Please note -- if you want firefox to *update* its cache for your redirected URL, you can use the `Web Developer Extension` to control firefox's change behavior temporarily to *always* check for a new version, then set it back to your normal setting. This is under Web Develoepr Extension -> Disable -> Disable Cache -> Check For Newer Version Of Page -> Check For Newer Version Of Page Every Time. – cptstubing06 Feb 03 '13 at 16:38
  • 1
    Whichever method you choose, the procedure is to change this setting to always check for a new version, then load your URL that has the cached redirect. It will then hit the server and get whatever new response exists for that url and update its cache with the new response. Then, you can set your cache check frequency back to your original value (default is "When page is out of date", but I am going with "Once per session" so that this exact scenario will be handled without my involvement now). – cptstubing06 Feb 03 '13 at 16:45
  • @cptstubing06 thanks for that tip! wish you had submitted it as a solution so I could upvote it as the best way to handle this when you don't want to clear you're entire cache. – Mercurybullet Apr 05 '13 at 20:32
  • FYI you might have to disable `DNS over HTTPS` in order for this to work as expected. – user2741287 Aug 20 '19 at 01:57
43

301 is just a normal cacheable response code. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2 says:

This response is cacheable unless indicated otherwise. 

So if you don't want it cached, your server needs to indicate otherwise through the normal headers used to control cache behavior.

You can also clear the cache manually.

Community
  • 1
  • 1
Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55
  • 7
    I believe it would be more straightforward to use a 302 instead, which is not cacheable by default. – Frank Farmer Dec 20 '11 at 01:14
  • 22
    @Boris Zbarsky: Isn't the question more 'How do I clear the cache' rather than 'How do I prevent the cache write from ocurring in the first place'? – Bobby Jack Mar 27 '12 at 09:58
  • 4
    The question sure seemed like "How do I keep myself from having to clear the cache" to me! – Boris Zbarsky Mar 27 '12 at 16:05
  • 18
    It sucks because you can't "shift-reload" a redirect even when you know it's wrong. Every other bad cached resource can be reloaded separately, but not these damn redirects. – Sam Watkins Sep 06 '12 at 02:18
  • 1
    I tried using 302 redirects from IIS, but recent versions of Firefox (and Chrome and Edge and IE) cache those as well, judging from their behavior. I found that opening and killing a Private window is the best way to test websites and avoid poisoning your browser's cache. – dsmtoday Jan 16 '16 at 01:41
  • The problem is that the fact that the server was sending a 301 redirect may have been due to a bug or data error. In this scenario, it is likely to be necessary to override the cached redirect for debugging purposes. – Stewart Feb 10 '23 at 10:40
25

I just experienced this problem, and for me it was two issues.

This particular domain name is routed through Cloudflare, so I had to set it to development mode. I think Cloudflare was caching the 301 redirect so it didn't have to send the request to the server. This step might not apply to you obviously.

Then, I simply cleared my Firefox cache (version 11) by going to Tools -> Options, clicking the Advanced button at the upper right, selecting the Network tab, and then clicking Clear Now under the section Cached Web Content. Note my cache was already set to 0, but I still needed to click the Clear Now button to get the redirect to stop being cached.

I'd be interested to know if anyone else can verify this.

Charlie Gorichanaz
  • 1,144
  • 1
  • 9
  • 20
  • 2
    +1. Your note on clearing the Firefox cache did fix this for me (as a user/client, not the website owner) for a particular URL where Firefox wasn't picking up a 301 having been updated. Thanks. – Jon Schneider May 21 '12 at 17:58
  • 1
    You can delete the just the cached redirect with this Firefox plugin: https://addons.mozilla.org/en-us/firefox/addon/cacheviewer-continued/ – Steve Oct 17 '12 at 15:28
10

I have found a solution for this that works on Firefox 26, after having an obsolete redirect cached for over a month and a restart.

  1. On the History menu, choose Show All History.
  2. In the search, type in the domain with the cached redirect issue to bring up a list of results.
  3. Right-click on one of them and choose "Forget about this site".

All cached pages, images and redirects for only that site will be removed from the cache. This lets you clear the redirect for your development website without clearing the rest of your cache.

As a side note, I think Firefox should only cache redirects for a few days at most. Caching them for over a month can make a simple mistake a big problem.

Malvineous
  • 25,144
  • 16
  • 116
  • 151
  • 2
    This works, but note that "Forget about this site" will also forget URL history (for auto-completion) and even saved passwords for the whole domain. Might not be what you want. – tanius Oct 09 '15 at 20:57
6

The developer tools built into recent versions of Firefox has a solution for this. First, turn off caching when the dev pane is open:

  • On any page, hit F12 to bring up developer tools
  • At the far right, click the gear icon "Toolbox Options"
  • Under Advanced Settings check the option Disable Cache (when toolbox is open)

Now any time you want to force a refresh of a cached page, load/refresh the page with the F12 dev toolbox open. Firefox will bypass the cache and get fresh data from the server.

I prefer this method because it doesn't change how the browser behaves for "normal" non-debug browsing, and you don't risk forgetting to restore a global setting to its original value.

Verified in Firefox 39

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54
5

One quick fix is to use a private browser window.

Costa Michailidis
  • 7,691
  • 15
  • 72
  • 124
3

A 301 indicates moved permanently. Therefore I see it to be reasonable to cache the response.

Have you tried setting the cache-control and expires headers?

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

Chris Diver
  • 19,362
  • 4
  • 47
  • 58
  • 3
    Sometimes we are developing, or migrating servers, or tracing a fault, and really need to turn this stuff off as it can really get in the way. – Jason Nov 23 '12 at 14:01
2

In Firefox Version 38.0

Menu -> Edit -> Preferences -> Advanced -> Network -> Clear Now

Worked for me.

Soorajlal K G
  • 778
  • 9
  • 20
1

301 means Moved Permanently and is cachable, so I think that's the "right" behavior for the browser. You should use 303 See Other.

jsz
  • 1,387
  • 9
  • 17
  • 5
    IE and Chrome cache 303 and the HTTP spec is being changed to allow caching it. See the drafts at http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-15 . So the only safe way to prevent redirect caching is to set explicit Cache-control headers. – Boris Zbarsky Aug 08 '11 at 13:29