Skip to main content

Posts

Showing posts with the label Install a Service Worker

Angular Service Worker Cache and return Requests

How to Cache and return Requests? After a service worker is installed and the user navigates to a different page or refreshes, the service worker will begin to receive fetch events. Got a minute? Check out this,  Angular 6 Questions | A Complete Guide Book The following example looks like this. self . addEventListener ( 'fetch' , function ( event ) {   event . respondWith (     caches . match ( event . request )       . then ( function ( response ) {         //Cache return response         if ( response ) {            return response ;         }                return fetch ( event . request );       })   ); }); What Is Angular Language Service? Th...

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...