简体   繁体   中英

Javascript clear browser cache for end user

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM