Skip to content

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.

  1. fetch: intercept requests and answer with event.respondWith(...)
  2. activate: delete old caches from previous versions
  3. install: open a cache and pre-cache the app shell (caches.open, cache.addAll)
  4. navigator.serviceWorker.register('/sw.js') from the page
Show answer & explanation

Correct order:

  1. navigator.serviceWorker.register('/sw.js') from the page
  2. install: open a cache and pre-cache the app shell (caches.open, cache.addAll)
  3. activate: delete old caches from previous versions
  4. fetch: intercept requests and answer with event.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.