1

Is there a way to clear browser cache using Javascript? When publishing a new release to an application, I sometimes have to tell my users to clear their browser cache to see the new changes.

The application is built using Vue.

Chris Eikrem
  • 496
  • 1
  • 5
  • 20
  • 1
    Does this answer your question? [Clear the cache in JavaScript](https://stackoverflow.com/questions/1011605/clear-the-cache-in-javascript) – GAMELASTER Feb 01 '21 at 09:51

1 Answers1

1

I developed a PWA in Vue which had a lot of caching to be able to work offline as well, so distributing a new release was kind of tricky, solution that I settled on was deploying a version.txt file along my release and then periodically fetching that file from my app and when versions from .env files and version.txt don't match then I call:

   caches.keys().then((keyList) => Promise.all(keyList.map((key) => caches.delete(key))));

to delete all cache, additionally I display a dialog that says new version is available and force a refresh so new content is served.

I hope this answer gives you an idea what you need to do to be able to publish a new version properly.

Mario Klisanic
  • 545
  • 2
  • 9
  • 18