PWA & Service Workers concept page: Service Worker as browser proxy for network requests, cache strategies (cache-first, network-first, stale-while-revalidate), Workbox library, manifest.json (installable), Push API + Notifications, Background Sync queue, offline-first patterns, PWA vs native trade-offs ADR. Four scenarios: SW intercepts fetch and chooses cache strategy, offline page when network down, push notification flow (tab closed), background sync queue.
Service Worker — origin-scoped event-driven worker, который может перехватывать fetch и использовать Cache API. User agent может завершить worker между событиями; долговечное состояние нельзя держать только в памяти процесса.
Registration содержит installing, waiting и active workers. Успешный install не означает немедленный control уже открытых pages, а skipWaiting/clients.claim меняют rollout semantics и требуют совместимости со старыми clients.
| Компонент | Роль в модели |
|---|---|
| Controlled Page | register and observe; controlled fetch; manifest discovery |
| Service Worker Registration | register and observe; install update |
| Installing or Waiting Worker | install update; precache version |
| Active Event Worker | controlled fetch; cache policy; network request; classified outcome |
| Versioned Cache Storage | precache version; cache policy |
| Network Origin | network request |
| Web App Manifest | manifest discovery |
| Offline and Update Telemetry | classified outcome |
A new worker opens a new cache namespace and precaches the minimal immutable shell inside install waitUntil. Any required fetch rejection fails the install and leaves the active version intact.
Проверяемый исход: The waiting worker is complete or absent; a partial cache is never promoted as a successful release.
The active worker receives a navigation fetch. It tries the network within policy, then returns a version-compatible offline document; API mutation failures are not replaced with fake success.
Проверяемый исход: Offline fallback is route/type aware, and the UI distinguishes cached content, unavailable data and queued intent.
A waiting worker activates after the old client set is safe to replace. Activate migration removes only caches not needed by any supported client, then new pages become controlled.
Проверяемый исход: HTML, chunks and data schema remain compatible during the transition; forced takeover is used only with a tested cross-version contract.
A cache write rejects because of quota or storage failure. The worker classifies the failure, keeps network behavior correct and emits minimized telemetry instead of treating cache success as guaranteed.
Проверяемый исход: The request still follows a valid network/error path, cache repair is bounded, and the UI never claims durable offline availability without verification.
cache_hit_ratio = policy_hits / eligible_fetches; separate navigation, immutable asset and API strategies instead of combining unlike denominators.offline_shell_bytes = Σ required_versioned_response_bytes + metadata_overhead; compare with measured quota and leave headroom for other origin storage.stale_age = response_time − origin_validation_time; a cache insertion timestamp is not necessarily the data creation time.Числа и bounds выше действуют только при названных units, population и assumptions. Ни паттерн, ни browser API сами по себе не задают SLA, capacity или correctness.
Диаграмма показывает standards-level lifecycle. Она не обещает install prompt, push delivery, Background Sync support, permanent browser storage или одинаковое PWA behavior на всех platforms.
Введите числа или выберите пресет