Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigate to new url in javascript, but force reload?

Tags:

javascript

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.

like image 551
carpii Avatar asked Mar 11 '23 22:03

carpii


1 Answers

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.

like image 152
motanelu Avatar answered Mar 13 '23 10:03

motanelu