This simple recipe will demonstrate how to have the service worker immediately take control of the page without having to wait for a navigation event.
To get started with service workers, you will need to have the service worker experiment feature turned on in your browser settings. If you have not done this yet, refer to the Setting up service workers recipe of Chapter 1, Learning Service Worker Basics. Service workers only run across HTTPS. To find out how to set up a development environment to support this feature, refer to the Setting up GitHub pages for SSL recipe of Chapter 1, Learning Service Worker Basics.
Follow these instructions to set up your file structure:
Copy the
index.html
,index.js
,service-worker.js
, andstyle.css
files from the following location:https://github.com/szaranger/szaranger.github.io/blob/master/service-workers/09/01/
Open a browser and go to
index.html
.Refresh the page. The status of the service...