Clear cache of browsers with javascript


Is it possible to clear the cache of Firefox and Chrome browsers via Javascript? With Internet Explorer I can do it, but not the ones mentioned above.

Dude, it did not work, I think the problem occurs because unless the user logged in remember me ... but, the problem occurs only when I close the browser, if I click on exit it works normally.

Have you seen anything like this?

If the user checks the check box, I'll add a cookie:

if (model.RememberMe)
     Response.Cookies["SistemaLeilao"].Value = model.UserName;
     Response.Cookies["SistemaLeilao"].Expires = DateTime.Now.AddMinutes(5);

When I click on the exit and the logoff is done, it works fillet, but when it closes the browser window without doing logoff everything is saved, and that is what I am disturbing.     

asked by anonymous 10.06.2014 / 14:27

4 answers


It is not possible, and if it were a huge security flaw, did you think you could clear the cache of anyone accessing your page?

What you can do is tell the browser not to cache your page , this can be done using one of these meta tags:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
10.06.2014 / 14:37

As stated in this response from Stack-EN , you can use:


to force the browser to reload the JS / CSS to the your page only. Clearing the cache of the whole browser is not possible.

07.07.2014 / 18:53

Well, cache is an important load balancer and broadband consumer, I do not advise you as a member of SOpt you use the @Laerte solution in every case, every case should be studied.

Imagine if your page had 500 Kb photos each, and you wanted to always display them in their original size, for example, a gallery from a social network. Whenever the user logs into the social network and accesses his gallery, it would be necessary for the browser to request this 500 Kb photo (as well as the others) since you would have "made the browser not cache your page". If you had let the cache store those images (locally) it would be much faster to load the site and lower the bandwidth consumption.

One solution, when you want to force something to be constantly updated and downloaded (updated in the cache), is to create a src of references to .CSS , .JS , imagens , put a variable via GET updated with a random value (% with%). This is also a SOen solution as quoted @ user7261.

I've come up with a similar solution here: Caching with AngularJS

24.02.2016 / 15:34

Preventing the browser from using the cache did not look good to me, at least in my scenario, so looking for a solution to this question, I saw many people using the following format:

<link rel="stylesheet" type="text/css" href="meu.css?v=<?=filemtime($file);?>">

But in the scenario I work with, every time the system is updated on the server, files that have not been changed are also overwritten, thus changing its modification date, forcing the browser to download the asset even if it has not been modified, which I think is very inefficient, since the use of cache is impaired.

The solution I found to do this only if the file was changed is to use a hash function, which will only change the hash if the contents of the file are actually modified.

<link rel="stylesheet" type="text/css" href="meu.css?v=<?=hash_file('md5', $file);?>">

I'm using both .js and .css files, which I thought was best, because if the file was not changed, it's best to let the cache work, otherwise the browser will download the asset again.     

21.06.2018 / 20:25