Is there any way I can force Firefox to NOT cache redirects (301 and 302)?
I am a web developer, and there are many times where I have to create or alter a 301 or 302 redirect. It is cumbersome to test immediate changes in Firefox because it caches redirects, so if I change the redirect server-side, and then hard refresh, the old redirect is cached, so the only way I can test the new one is by deleting my cache or starting a private browser session.
That being said, it is not particularly difficult to work around, but it is annoying, especially when I forget to do so, and it looks like my new redirect is not working, until I remember to delete the cache or start a new private session.
I understand why it is beneficial to cache redirects for normal use, but I would like to disable the behavior for debugging purposes.
Solution 1:
You can set an option to turn off consulting the cache if you have the developer toolbox panel open (as it happens with F12).
To set this option:
- On any page, hit F12 to open the developer toolbox panel.
- Click the gear icon in the top right of that panel.
- There, check "Advanced Settings → Disable Cache (when toolbox is open)".
Cache redirects will still be cached from visits without the developer toolbox panel open, but that cache is not consulted and not updated as long as the developer toolbox is open. So you only temporarily force Firefox to not cache redirects or serve redirects from cache, but it could be enough for your use case.
Verified in Firefox 41. Adapted from Ryan Bemrose's answer to another question.
Solution 2:
I completely understand why it is beneficial to cache redirects in 99% of situations, but is there anyway to disable that behavior?
Well, if you are doing this from a web server development standpoint, then expecting browser “cache at all costs” behavior to be altered for your “endless development tweaking” needs is the wrong way to attack this beast. When you are debugging web server redirects, you need to focus on checking the header output and not full page rendering output which browsers provide.
So instead, I would recommend learning how to use curl
and the -I
option from the command line to return only headers which is very useful for debugging 301 and 302 redirects. From the command line. As explained in the official curl
man page, the -I
option is:
-I/--head
(HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on a FTP or FILE file, curl displays the file size and last modification time only.
For example, do a curl -I google.com
and the output will be something like this:
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sat, 11 Apr 2015 04:37:42 GMT
Expires: Mon, 11 May 2015 04:37:42 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic,p=0.5
And if you wanted to follow the whole redirect chain via headers, then add the -L
option (aka: --location
) to the command like this:
curl -I -L google.com
And the output of that command following the location redirect chain would be something like this:
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Sat, 11 Apr 2015 04:48:14 GMT
Expires: Mon, 11 May 2015 04:48:14 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic,p=0.5
HTTP/1.1 200 OK
Date: Sat, 11 Apr 2015 04:48:14 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=69d90e4d7a0fcbbb:FF=0:TM=1428727694:LM=1428727694:S=1xqS-toEoa5saQ7n; expires=Mon, 10-Apr-2017 04:48:14 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=pkHjv88MsTB_eB1OqqcMm03kTkFNOSaN4ZEiE5iGViEt7AiJWBc6R-0qJ5s1xu3i5Peg5aHOBHyr7n4-oAxyEE2cL_dBPRLYODst0H-Ztfgrf_6LYXXlix9eghSB8Hzc; expires=Sun, 11-Oct-2015 04:48:14 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic,p=0.5
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding
Note the header response of HTTP/1.1 301 Moved Permanently
as well as Location: http://www.google.com/
. If your web development goal is to test things like Apache rewrite rules and redirects, curl -I
is the best tool to help you see what your tweaks are doing.
And after those tweaks are finalized and perfected, then do a final run in a real browser to see it all come to life.
Solution 3:
In Firefox Firebug, under the Net
tab, there is an option called "Disable Cache". I flip this on when doing redirect testing, and I have it flipped off otherwise.
Solution 4:
Go to about:config
and set both browser.cache.disk.enable
and browser.cache.memory.enable
to false. This is the same as checking "Disable Browser Cache".