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