OrderNot attempted
Service worker lifecycle
Order the service worker lifecycle for a first visit.
Drag the rows, or use the arrows, to put them in order from first to last.
fetch: intercept requests and answer withevent.respondWith(...)activate: delete old caches from previous versionsinstall: open a cache and pre-cache the app shell (caches.open,cache.addAll)navigator.serviceWorker.register('/sw.js')from the page
Show answer & explanation
Correct order:
navigator.serviceWorker.register('/sw.js')from the pageinstall: open a cache and pre-cache the app shell (caches.open,cache.addAll)activate: delete old caches from previous versionsfetch: intercept requests and answer withevent.respondWith(...)
A new worker waits until no tab uses the old one (or calls skipWaiting() / clients.claim()). Service workers need HTTPS (localhost is exempt) and only control pages within their scope.