The following figure illustrates how a service worker lives:
It is clear from the diagram that first a service worker needs to be installed. Then it triggers certain events which we can catch in our code to handle different stuff. Let us now discuss how to implement all of these steps, in detail.