PWA: How does the service worker know when I deploy new files?


As the www folder generated contains files which names never change, how does the browser know when there is a new file to download instead of using the cached one ? I’ve seen that the files generated by another project, anular-cli contain a hash number forcing the browser to download them after deployment


ok, I did some progress understanding it.

services-workers.js contains this route:

// dynamically cache any other local assets
self.toolbox.router.any('/*', self.toolbox.cacheFirst);

Which means

If the request matches a cache entry, respond with that. Otherwise try to fetch the resource from the network. If the network request succeeds, update the cache. This option is good for resources that don’t change, or have some other update mechanism.

I’m using ionic2 only for PWA. I’ve removed Cordova and I’m deploying the www folder, generated with build --prod, simply copying it into my CDN.

How does the service worker know when I deploy new files ?

I’m looking to deploy my first ionic-driven site - did you find anything regarding cache-busting for updates?

as we are still in dev mode (no live yet), for now we are just using global.toolbox.router.default = global.toolbox.fastest;

later on we’ll tweak it better…

1 Like

Have you gone any further with this approach? This is something I have been wondering also, how to let the browser know that sub-modules of main.js have also been updated.

Anyone ever find an answer for this? I’d like to be able to rebuild the www folder with a change or two from src and the service worker update based on this, rather than having to manually update the service-worker.js file itself each time?