navigate to new url in javascript, but force reload?

javascript

Solution

There's no out of the box solution. The easiest way is to add another parameter to the URL that will break the cache. For example

 window.location = "/server/url?timestamp=" + (new Date()).getTime()

Every single time you run it, the timestamp will change and the browser won't have that page in the cache.

Problem

Javascript provides the `location.reload(nocache)` API. When the 'nocache' param is true, it will force reload the current url from server bypassing the browser cache. Is there an equivalent way to do this when navigating to a new url via `window.location.href = url;` ? I have a chat application which detects the version the client is running compared to what the server expects, and if they differ it prompts the client to navigate to the latest version url. But I'm finding when I issue this, many clients are still using cached scripts.

Original source