PWA / Service worker breaking production deployments
See original GitHub issueEDIT: Issue appears to be with Firebase only
Service workers aren’t refreshing index.html and therefore new deploys are showing old bundles.
This means production websites or really all deployed sites that use a single url/domain can not be updated.
PR #2441 - Is a hotfix (if needed) that just removes the service worker and updates docs to say they have been disabled temporarily.
@gaearon @timer @jeffposnick @addyosmani
Steps to reproduce
create-react-app sw-test
cd sw-test
npm install
npm run build
cd build
Deploy with firebase
firebase deploy
- Visit site https://[project].firebaseapp.com. Confirm working.
- Change app.js
npm run build
cd build
deploy firebase
Check website
- Visit site again and no changes shown. DevTools shows SW is providing index.html and old bundles.
- Force refresh a few times. No difference.
- Delete service worker.
- Refresh.
- See correctly updated site.
Can someone else confirm this is affecting them?
I am hoping I am doing something wrong and this isn’t affecting every production deploy.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:27
- Comments:20 (13 by maintainers)
Top Results From Across the Web
Service worker in production - Angular
This page is a reference for deploying and supporting production applications that use the Angular service worker. It explains how the Angular service ......
Read more >Strategies for Service Worker Caching for Progressive Web ...
Here's a quick summary of what this post covers: Service Worker caching enables offline first apps. In case its a broken deployment you...
Read more >What should I do to update service workers and cached PWA ...
I was looking into making my app work as a PWA and I was wondering how to invalidate the cache for existing users...
Read more >The service worker lifecycle - web.dev
A deep-dive into the service worker lifecycle. ... The install event is the first event a service worker gets, and it only happens...
Read more >Handling Service Worker updates – how to keep the app ...
For production readiness, we need to make sure our Service Worker will be ... place not to cut off our users from actually...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those who come across this issue, here is how you should be able to fix it for Firebase Hosting. Edit your
firebase.json
and add headers like so:What you’re running into with https://cra-sw.firebaseapp.com/ is described in item 5 of the “Offline-First Considerations”, and is due to
service-worker.js
being served with HTTP caching headers.It’s unfortunately a common pain point, since many hosting providers will default to a medium-length cache lifetime for assets like
.js
files. Updating your web app’s assets relies on detecting an updatingservice-worker.js
file, and that is complicated when the browser’s cache comes into play. (The cache headers are always ignored if the file is over 24 hours old; it there’s more historical detail here.)The service worker specification was changed to cause HTTP caching of
service-worker.js
to only happen when a developer explicitly opts-in, and Firefox has already implemented that change in FF53+.Chrome has unfortunately not caught up, and still honors the HTTP caching headers. I was just asking about the status of this internally yesterday, and I’ll point the relevant folks to these discussions, given the larger audience that is likely to inadvertently run into this.