Applications Static or cached unchanging according to the RFC8246 specification:
Add the code below at the beginning of the tag "<head>
"
<meta name="Cache-Control" content="no-cache">
Alternatively, use:
<meta name="Cache-Control" content="max-age=0,must-revalidate">
Aplicações Dinamicas:
The answers are liars, I could use a more cute term "mistaken", but for no apparent reason, they are incorrect, mainly with regard to "being impossible" and still congratulate you for a gambiarra, yes, it is gambiarra, from what I saw on the island, Versionar does absolutely nothing, inclusive, no need to Versionar, just reload the page twice in a row the browser itself will see if there are changes, I did not find what you were looking for here, but I will leave a simple code that I created, based on the official documentation showing how: https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete.
Step 1: First, go to your site, open the console (F12), at the top, find the menu: "Application", "Application" or "Applications", click on it, now, in the side menu, find "Cache", click on "Cache" or "Cache Storage". (whichever comes first)
Write down the name you see there, in my case: "devsite.pwa_RUNTIME_V3", if nothing appears, your problem is different, should be with a proxy or other intermediary any.
Step 2: Now create a Cookie for all users who access your site, use the name "version" and value "2.0", no encryption, leave it for later, should be a common cookie.
Step 3: Cut out your script and put inside the "Else" below, change "devsite.pwa_RUNTINE_V3" to the name you wrote down on step 1, additionally, change "/Assets/css/style.css" to the path of the files or images you want to update, including the file you want to put this code in, save the file, clear your browser cache, and update the page.
console.info('script:', 'verificar versão...');
function verify(code){var cookiestring=RegExp(code+"=[^;]+").exec(document.cookie); return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./,"") : "");}
if(verify('version') !== '2.1'){
caches.open('devsite.pwa_RUNTINE_V3').then(function(cache) {
cache.delete('/assets/css/style.css');
cache.delete('/assets/js/script.js');
})
localStorage.clear();
console.info('script:', 'confirme a atualização.');
alert("Portuguese: Precisamos atualizar a página, esta é uma versão antiga.\n English: We need to update the page, you are on an old version.\n Español: Necesitamos actualizar la página, estás en una versión anterior.");
console.info('script:', 'recarregando...');
location.reload(true);
} else {
//cole o script aqui.
}
If all goes well and probably will, you will see an Alert, do not click "ok", first change the value of the cookie you created in step 2, to "2.1", now yes you can click "ok", the page will be automatically reloaded and its cache will be cleared.
You’re welcome.
Example of how to clear the cache at Logout
<button class="reset">Sair</button>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<script>
$(".reset").click(function(){
caches.open('devsite.pwa_RUNTINE_V3').then(function(cache) {
cache.delete('/assets/css/style.css');
cache.delete('/assets/js/script.js');
cache.delete('/dashboard.html'); //nome e local correto do arquivo
})
localStorage.clear();
})
</script>
I’m just not surprised that you can clear the IE cache via JS because, after all, security has never been the strong point of IE.
– Oralista de Sistemas
window.onunload
– pnet
The answer is perfect, speaks the reality, the question and the statement are completely wrong.
– user6026
I just wanted to help a friend. The question was for him. It is not justification this no, I just supported myself in his doubt that I now understood that it was mine too. But it was worth to all.
– pnet