Skip to main content

Posts

Showing posts with the label How To Install a Service Worker?

How To Register, Install and Cache A Service Worker in Angular5? How do We do?

How To Register A Service Worker? To install a service worker you need to kick start the process by registering it in your page. This tells the browser where your service worker JavaScript file lives. You can call below register () every time a page loads without concern; the browser will figure out if the service worker is already registered or not and handle it accordingly. if ( 'serviceWorker' in navigator ) {   window . addEventListener ( 'load' , function () {     navigator . serviceWorker . register ( '/sw.js' ). then ( function ( registration ) {       // If Registration was successful       console . log ( 'Success Registration - ' , registration . scope );     },     function ( err ) {       // If Registration was failed!       console . log ( 'Failed Registration - ' , err );     }...