Angular Service Worker Life Cycle

Install a Service Worker in Angular

How to Install a Service Worker?
After a controlled page kicks off the registration process, let's shift to the point of view of the service worker script, which handles the install event.

The following example looks like this.
self.addEventListener('install', function(event) {
  // To perform install steps
});

Inside of our install callback, we need to take the following steps -
1.      Open a cache
2.      Cache our files
3.      Confirm whether all the required assets are cached or not

The following example looks like this.
var CACHE_NAME = 'my-site-cache-v1.0';
var urlsToCache = ['/','/styles/site.css','/script/site.js'];

self.addEventListener('install', function(event) {
  // Perform install steps
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(urlsToCache);
      })
  );
});

Got a minute? Check out this, Angular 6 Questions | A Complete Guide Book
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Install a Service Worker in Angular Install a Service Worker in Angular Reviewed by Anil Singh on 11:07 PM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^