In my web application I am setting window.location
to navigate to a different page, but for some reason Firefox shows an old version of that page.
Using Firebug I detected that the browser doesn't even send an HTTP request, it simply uses an older version of that page (not even the last one) and displays it.
The page itself has all the usual headers to prevent caching which works perfectly when I browse my pages using links or manual input. The problem only occurs when seting window.location
.
Is this a Firefox problem or something to expect from any browser? Can this behaviour be changed?
When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache. You can then close out of Developer Tools.
A proxy HTTP server that forwards your message to the server would never cache anything but a GET or a HEAD request.
location. reload() takes an additional argument skipCache so that with using window. location. reload(true) the browser will skip the cache and reload the page from the server.
All HTTP requests that the browser makes are first routed to the browser cache to check whether there is a valid cached response that can be used to fulfill the request. If there's a match, the response is read from the cache, which eliminates both the network latency and the data costs that the transfer incurs.
You could just add a random parameter to the page URL in order to have the browser issue a new request.
So instead of using
window.location = "my.url/index.html";
use
window.location = "my.url/index.html?nocache=" + (new Date()).getTime();
You can use location.reload with a true argument, which will always bypass the cache.
window.location.reload(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With