简体   繁体   中英

How to clear service-worker.js cache on firebase

How do I force client machine to clear the service worker cache after I deploy to firebase? Clients still getting old code when they refresh the page

screenshot

I believe your problem is that the service worker has cached your page's index.html and the client is being served with that from the cache when there's actually a fresh one available in the background. The client always gets the old index.html which points to the old JS, CSS etc.

You have basically two options:

If your service-worker.js lists all files that should be cached , just simply update your service-worker.js and the cache name . The browsers automatically update the SW when they see the change. They automatically check to see if there's even a single-byte change.

If your SW dynamically caches files and returns them from the cache the next time they are requested, you should programmatically check for updates every time you serve something from the cache. You can find code examples here: https://serviceworke.rs/strategy-cache-and-update_service-worker_doc.html

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