clear browser cache and history via javascript and load latest js files
javascript, jquery
Solution
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 ;)
Problem
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.