question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PWA / Service worker breaking production deployments

See original GitHub issue

EDIT: 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:closed
  • Created 6 years ago
  • Reactions:27
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

65reactions
mbleighcommented, Jun 1, 2017

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:

{
  "hosting": {
    "headers": [
      { "source":"/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}] }
    ]
  }
}
24reactions
jeffposnickcommented, Jun 1, 2017

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.

screen shot 2017-06-01 at 10 54 07 am

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 updating service-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found