How to update a service worker?

Technology CommunityCategory: PWAHow to update a service worker?
VietMX Staff asked 3 years ago

There will be a point in time where your service worker will need updating. When that time comes, you’ll need to follow these steps:

  • Update your service worker JavaScript file. When the user navigates to your site, the browser tries to redownload the script file that defined the service worker in the background. If there is even a byte’s difference in the service worker file compared to what it currently has, it considers it new.
  • Your new service worker will be started and the install event will be fired.
  • At this point the old service worker is still controlling the current pages so the new service worker will enter a waiting state.
  • When the currently open pages of your site are closed, the old service worker will be killed and the new service worker will take control.
  • Once your new service worker takes control, its activate event will be fired.