Simple implementation
window.addEventListener('load', function() { navigator.serviceWorker.register('/sw.js').then(function(registration) { // Registration was successful console.log('ServiceWorker registration successful with scope: ', registration.scope); }, function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }); });
Update Cache
self.addEventListener('install', function(event) { Event. waitUntil (self. skipWaiting())//This will trigger the activate event });
navigator.serviceWorker.addEventListener('controllerchange', function (ev) { //A prompt bar appears, prompting you to click the refresh page to update the local cache });