Populating your cache

suggest change

After 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'
      ]);
    })
  );
});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents