Force a reload of page in Chrome using Javascript [no cache]

I need to reload a page using JavaScript and ensure that it does not pull from the browser cache but instead reloads the page from the server.
[As elements of the page will have changed in the interim]

On IE and FF I found that the following code worked fine;


However it does not work on Chrome or Safari.

I tried the following, but also to no avail;


Is there a solution to this issue?


After looking into this I have found that this issue is HTTP Protocol handling;

  1. Chrome sends a request with Pragma: no-cache HTTP field
  2. Server responds with Last-Modified: DATE1 field
  3. JS uses location.reload(true) to force a reload from server not cache
  4. Chrome sends a request with If-Modified-Since: DATE1 field
  5. Server responds with HTTP Status 304 Not Modified

The server application is at fault for not noticing the state change in the dynamic page content, and thus not returning a 200.
However, Chrome/WebKit is the only browser that sends a If-Modified-Since field when the JS location.reload(true) is called.

I thought I would put my findings here in-case someone else comes across the same issue.

You can use this hack:

        url: window.location.href,
        headers: {
            "Pragma": "no-cache",
            "Expires": -1,
            "Cache-Control": "no-cache"
    }).done(function () {

To ensure the page isn’t loaded from cache you can add some unique number to query:

window.location = location.href + '?upd=' + 123456;

You also can use date instead of 123456

This is what I do to ensure my application file is force reloaded on chrome:

    var oAjax = new XMLHttpRequest; 'get', '/path/to/my/app.js' );
    oAjax.setRequestHeader( 'Pragma', 'no-cache' );
    oAjax.onreadystatechange = function() {
        if( oAjax.readyState === 4 ) {

Try window.location = window.location

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts