The service worker life cycle
The life of your service worker begins when a user first visits your page. The service worker is downloaded and begins running. It may go idle for a time when not needed, but can then restart when required.
This always on functionality is what makes the service workers useful for push notifications. It also makes service workers a bit unintuitive to work with (more on that to come). However, let's take a deep look at the life and death of a service worker on a typical page.
First, the service worker is installed, if possible. All service worker installations will start with a check to see whether the technology is supported by the user's browser. As of now, Firefox, Chrome, and Opera have full support, and other browsers do not. Apple, for one, views service workers as experimental technology, indicating that they're still on the fence about the whole thing.
If the user's browser is modern enough, the installation begins. The script (for example, sw.js
) is installed...