When a Service Worker runs for the first time, an event is fired within it; the Install event.
The browser wont let this new SW take control of pages until its install phase is completed; we are in control of what that involves.
So we can take advantage of that to get everything we need from the network, and create a cache for them as well.
For the Install event, we need to add a new listener in our SW file.
self.addEventListener('install', function(event) {
event.waitUntil(
//...
);
})
even.waitUntil()
takes a promise, and cache.open()
returns one.
The method addAll()
also returns a promise.