October 2017
Intermediate to advanced
302 pages
7h 27m
English
Before we get to the good stuff, we need to talk about extendable events.
Once our service worker is activated and installed, it may immediately go into "waiting" mode--waiting for an event to occur to which it must respond. However, we don’t want it to go into waiting mode while we're in the middle of opening the cache, which is an asynchronous operation. So, we need a way of telling our service worker, "Hey, don’t consider yourself fully installed until the cache is populated."
The way we do so is via event.waitUntil(). This method extends the life of an event (here, the install event) until all Promises within it are resolved.
It looks as shown:
self.addEventListener('install', event => { event.waitUntil( // Promise ...Read now
Unlock full access