October 2017
Intermediate to advanced
370 pages
8h 57m
English
For this example, we want the service worker to cache a few resources--some pages and assets--so that the site can be used offline. The service worker API defines an install event that can be used to define what should happen when the service worker is installed. Typically, at this point, we'd want to cache all the pages and resources that will be needed when the user is offline. When the service worker is installed, we can open a cache (pwa-cache) and add items to it like this:
self.addEventListener('install', e => { e.waitUntil( caches.open('pwa-cache').then(cache => { return cache.addAll(['index.html', 'amp.html', 'extra.js', 'manifest.json']) }) )});
We can then intercept page requests by listening ...
Read now
Unlock full access