Service Worker loading stale / outdated cached files (cli 3.11.5 / sdk 35 and cli 3.11.7 / sdk 36)

Whenever I upload a new build to our server, any browser that had opened the previous version continues to use that version unless the cache is cleared, or a full refresh is triggered. Even then, refreshing normally after that will sometimes go back to the older version. This seems to trace back to the service worker. When an old version is erroneously loaded, the Chrome network log says it was served by the service worker. This sounds very similar to which was supposed to be fixed in but even after updating to cli 3.11.5, clearing all my browser data, making sure it always loads a version from after that updated build, and then doing another update, the problem persists.

This was on @expo/webpack-config@0.10.1, I just noticed there’s a newer version and it generates a different register-service-worker.js. I’ll report back if @expo/webpack-config@0.10.11 fixes the problem.

That did not fix anything. Even forcing the app to refresh if a newer version is detected on the server doesn’t work. Why does Expo use service workers anyway? Is there a way to NOT use service workers?

For what it’s worth, I’ve been running into the same problem and have been unsuccessful in fixing it. IMO, the default caching policies that Expo passes to Workbox for caching assets are way too aggressive for defaults.

This should have been fixed for a while now. I think the unfortunate nature of this error has caused any legacy service workers to remain registered. ⌘+shift+R or manually unregistering service workers should remove the legacy aggressive workers.

It continues even after unregistering the service workers. The new ones are just as aggressive.

I’m actually also facing this still, for a project I just created.

My solution (for deploying to netlify) was to add a _headers file to the deployment folder.

Update This actually did not solve it.

"scripts": {
 "predeploy: "expo build:web && yarn headers",
  "headers": "echo \"/*\n  cache-control: max-age=0\n  cache-control: no-cache\n  cache-control: no-store\n  cache-control: must-revalidate\" > web-build/_headers",
  "deploy": "netlify deploy --prod"
1 Like