Clear the Cache in JavaScript

Auto clear cache from browser

You have 3 options:

  1. Put this in the head section of your html page :
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

This will make your app to not cache anything at all ( at least you can keep it during
development)


  1. Use hard refresh for example ctrl+f5 if you are using chrome every time you reload.

  2. Use a Cache killer plugin for your browser. There's a bunch of them out there, you just install them and enable them whenever you want.

How to clear cache of service worker?

Use this to delete outdated caches:

self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});


Related Topics



Leave a reply



Submit