Answer
What is the service worker lifecycle?
A service worker moves through four stages: install (fired once when the browser first downloads a new or changed worker), waiting (if an old version still controls open tabs), activate (once it takes control, typically after all old tabs close or skipWaiting() is called) and idle, where the browser terminates it between events to save memory.
Install and activate
The install event is the place to precache assets. The activate event is the place to clean up old caches from a previous version.
The waiting phase
By default, a new service worker waits until every open tab controlled by the old one is closed, preventing two versions running simultaneously. self.skipWaiting() bypasses this.
Termination
Browsers kill idle service workers after roughly 30 seconds of inactivity to save resources, then wake them again on the next fetch, push or sync event.