Skip to content

Commit f4a6d82

Browse files
feat(aio): provide noop service worker file
Use this file if we need to turn off the service worker in deployed sites in an emergency where the worker has a bug that is blocking the application from working. Closes #16897
1 parent 0c691af commit f4a6d82

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎aio/src/noop-worker-basic.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* A simple, no-op service worker that takes immediate control.
3+
* Use this file if the active service worker has a bug and we
4+
* want to deactivate the worker on client browsers while we
5+
* investigate the problem.
6+
*
7+
* To activate this service worker file, rename it to `worker-basic.min.js`
8+
* and deploy to the hosting. When the original worker files cache
9+
* expires, this one will take its place. (Browsers ensure that the expiry
10+
* time is never longer than 24 hours, but the default expiry time on Firebase
11+
* is 60 mins).
12+
*/
13+
14+
// Skip over the "waiting" lifecycle state, to ensure that our
15+
// new service worker is activated immediately, even if there's
16+
// another tab open controlled by our older service worker code.
17+
self.addEventListener('install', function(event) {
18+
event.waitUntil(self.skipWaiting());
19+
});
20+
21+
22+
// Get a list of all the current open windows/tabs under
23+
// our service worker's control, and force them to reload.
24+
// This can "unbreak" any open windows/tabs as soon as the new
25+
// service worker activates, rather than users having to manually reload.
26+
self.addEventListener('activate', function(event) {
27+
event.waitUntil(self.clients.claim());
28+
});

0 commit comments

Comments
 (0)