Question concerning caching a PWA application with a serviceworker


i have a PWA application that i try to cache with Cloudflare.

The caching work very well but the problem it’s that then when we have a code update, the serviceworker doesn’t take the new update and stay with the old version. And sometimes, the serviceworker take the new update but then is back with the old version.

I tried a lot of different configuration but i was not able to make it work. If you could point me to the right configuration it will be very appreciated :slight_smile:

Here is the HTACCESS, i use :

Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0

And for Cloudflare, i just add an page rule with :
Cache Level : Cache Everything
Edge Cache : 2 Days
Origin Cache Control : I tried with ON & OFF

The ideal behavior would be that the cloudflare cache serve the files faster because a PWA is quite heavy. But when I updated the code, the cache serve the new file and permit the update for the service worker.

Thanks for your reading and your response ! :wink: