Question

Disabling cache of Service Worker in App platform (Static site)

Posted July 14, 2021 76 views
JavaScriptReactDigitalOcean App Platform

I am having problems with the service worker registration, most likely due to caching issues. Guidelines say that service-worker.js should not be cached.

Is there a way to disable caching of some files like this in static sites of app platform?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hey there! Unfortunately there isn’t currently a way to disable caching within static sites at this time. Having more control over caching may be an option that we will have in the future but isn’t currently something offered. I would suggest adding your vote to our ideas page: https://ideas.digitalocean.com/ideas/APPX-I-227

  • Hi @webdever, adding some context to @njw’s answer:

    App Platform caches your app in two places: the browser and the CDN. On the browser we set a 10 second expiry, and on the CDN we set a 24 hour expiry. We do this so that can both cache your website to improve performance but also ensure that your users always get the most recent version. When the browser’s cache expires, it will fetch it directly from the closest CDN point with minimal latency.

    Despite the CDN cache being valid for 24 hours, we explicitly purge the CDN cache every time you deploy your app so the CDN will pick up the new deployment.

    Is the cache-control header blocking your service worker from being registered at all?