clear browser cache and history via javascript and

2020-06-21 04:32发布

how to clear browser cache and history via javascript I found some links like:-

How to clear browser history oan clear cache?

how to clear browser hash history in javascript

but they do not properly described on how this can be achieved via javascript ( or jQuery)

I require this so that the user do not have to do a [Ctrl+F5] or manually clear cache and the most recent version of javascript file is loaded in the browser.

The main aim is to load the latest javascript files every time the user visits the website. My application in ASP.NET MVC based and javascript files are included in .csHtml file.

2条回答
Bombasti
2楼-- · 2020-06-21 05:12

There are other ways to prevent a JavaScript file (or other files) from being cached.

Simply append some dummy parameters to the end of the url. For example -

http://www.yourCoolSite.com/resources/js/main.js?r=SOME_RANDOM_VALUE

You would optimally do this on the server side. In PHP, this would look something like this -

echo "http://www.yourCoolSite.com/resources/js/main.js?r=".time();

Using the time() function, we append the current epoch timestamp to the URL and therefore guarantee* that the file will appear different to the browser each time.

* Until 2038 that is ;)

查看更多
够拽才男人
3楼-- · 2020-06-21 05:15

call window.location.reload(true) for a ctrl+F5 from script. :)

查看更多
登录 后发表回答