Slide 19
Slide 19 text
const staticCacheName = 'static';
const version = 1;
const updateCache = () => (
caches.open(staticCacheName + version)
.then(cache =>
cache.addAll([
'/offline-page.html',
'/assets/css/main.css',
'/assets/js/main.js'
]);
);
);
self.addEventListener('install', function (event) {
event.waitUntil(updateCache());
});
self.addEventListener('fetch', function (event) {
event.respondWith(fetch(event.request));
});
• Default: just fetch
• Override default
• Intercept network requests to:
• fetch from the network
• read from the cache
• construct your own response
fetch events