In this recipe, you will learn how to use a service worker by demonstrating the workflow and logging the steps so we can follow the flow.
The features we are going to implement are as follows:
A button to register a service worker
A button to reload the document
A button to unregister the service worker
The buttons can be pressed in any order. You can also specify the service worker script URL and scope to simulate different test cases.
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.