admin管理员组

文章数量:1405153

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 pared 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.

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 pared 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.

Share Improve this question edited Oct 16, 2016 at 8:57 Nurjan 6,0936 gold badges37 silver badges56 bronze badges asked Oct 16, 2016 at 7:54 carpiicarpii 2,0114 gold badges21 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

本文标签: navigate to new url in javascriptbut force reloadStack Overflow