Reputation: 21
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
Upvotes: 1
Views: 1849
Reputation: 5253
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
Upvotes: 1