So, I have an HTML page with service worker, the service worker cache the index.html and my JS files.
The problem is when I change the JS, the change doesn't show up directly on the client browser. Of course in chrome dev-tools, I can disable cache. But in chrome mobile, how do I do that?
I tried to access the site settings and hit the CLEAR % RESET button. But it still loads the old page/load from cache. I tried to use other browser or chrome incognito and it loads the new page.
Then, I try to clear my browsing data (just cache) and it works.
I guess that's not how it should work right? my user won't know if the page is updated without clearing the chrome browser cache.
Typically you update the
CACHE_NAME
in your service workers JS file so your worker installs again:Alternatively, to clear the cache for a PWA:
to list the names of the cache keys, then run:
to delete a cache key by name (i.e., my-site-cache). Then refresh the page.
If you see any worker-related errors in the console after refreshing, you may also need to unregister the registered workers:
I'm not convinced any of this will make it to spec.
Use this to delete outdated caches:
If you know the cache name you can simply call
caches.delete()
from anywhere you like in the worker:And if you wanted to wipe all caches (and not wait for them, say this is a background task) you only need to add this: