Populating your cache
suggest changeAfter a service worker is registered, the browser installs it and later activates it. Service workers run only in a secure context. In the worker, self is the global object. Top-level this is that global in a classic worker script and is undefined in a module.
Install event listener
this.addEventListener('install', function(event) {
console.log('installed');
});
Caching
event.waitUntil keeps the install running until the cache is filled. cache.addAll fails the whole install if any request fails. The example uses the Cache API.
this.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.addAll([
/* Assets that need to be cached */
'/css/style.css',
'/js/app.js',
'/images/snowTroopers.jpg'
]);
})
);
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents