React - service worker won't unregister when updating


Topic: React - service worker won't unregister when updating production build

ytec pro premium priority asked 6 years ago

Expected behavior

When updating the production build, the old service worker should unregister, so that it won't try to use old cached js files.

Actual behavior

Updated service worker just works for new visitors, old users need to delete their browser files to get the website working again.


Anna Morawska staff answered 6 years ago

Hi there, do you use create-react-app as a boilerplate?


ytec pro premium priority commented 6 years ago

Yes, just like you configured it. Didn't change much in the stack.


ytec pro premium priority commented 6 years ago

I see there is implementation for updating the serviceworker. But the serviceworker only updates if its different to the old one. The problem is, that there are some cached files that break the site when updating a new build. Users will have white screens until they clear or disable their browser cache. So its not the serviceworker file itself but it needs to update the cached files.


Anna Morawska staff answered 6 years ago

It's strange, it has never happened to me before - in general, when you create a new build, the CRA scripts rename your files if there is even one-bit difference in the file.

How did you test it? Working with service workers can be tricky - if you make a change to your service worker, then reloading the page won't kill the old one and activate the new one (it detects the change by requesting the service worker file each time and comparing the old and the new byte-for-byte). This is because the old window is never actually closed, meaning there's never a time to swap them out – you need to kill the tab completely then reopen it.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB React
  • MDB Version: 4.9.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No
Tags