From db3e65fb1786179930704868f578429e47c399bf Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 30 Jan 2018 14:08:23 -0800 Subject: [PATCH] docs(service-worker): describe safety-worker.js in SW guide (#21921) PR Close #21921 --- aio/content/guide/service-worker-devops.md | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/aio/content/guide/service-worker-devops.md b/aio/content/guide/service-worker-devops.md index f9ae460a91..0670eb2ee0 100644 --- a/aio/content/guide/service-worker-devops.md +++ b/aio/content/guide/service-worker-devops.md @@ -290,20 +290,42 @@ out of date. Right click the Cache Storage title and refresh the caches. Stopping and starting the service worker in the Service Worker pane triggers a check for updates. -## Fail-safe +## Service Worker Safety Like any complex system, bugs or broken configurations can cause the Angular service worker to act in unforeseen ways. While its design attempts to minimize the impact of such problems, the -Angular service worker contains a failsafe mechanism in case +Angular service worker contains several failsafe mechanisms in case an administrator ever needs to deactivate the service worker quickly. +## Fail-safe + To deactivate the service worker, remove or rename the `ngsw-config.json` file. When the service worker's request for `ngsw.json` returns a `404`, then the service worker removes all of its caches and de-registers itself, essentially self-destructing. +### Safety Worker + +Also included in the `@angular/service-worker` NPM package is a small +script `safety-worker.js`, which when loaded will unregister itself +from the browser. This script can be used as a last resort to get rid +of unwanted service workers already installed on client pages. + +It's important to note that you cannot register this worker directly, +as old clients with cached state may not see a new `index.html` which +installs the different worker script. Instead, you must serve the +contents of `safety-worker.js` at the URL of the Service Worker script +you are trying to unregister, and must continue to do so until you are +certain all users have successfully unregistered the old worker. For +most sites, this means that you should serve the safety worker at the +old Service Worker URL forever. + +This script can be used both to deactivate `@angular/service-worker` +as well as any other Service Workers which might have been served in +the past on your site. + ## More on Angular service workers You may also be interested in the following: