JavaScript Workers Populating your cache


After your service worker is registered, the browser will try to install & later activate the service worker.

Install event listener

this.addEventListener('install', function(event) {


One can use this install event returned to cache the assets needed to run the app offline. Below example uses the cache api to do the same.

this.addEventListener('install', function(event) {
  event.waitUntil('v1').then(function(cache) {
      return cache.addAll([
        /* Array of all the assets that needs to be cached */