Перейти к основному содержимому

Service-worker caching contract (HTML network-only, kill switch)

Generated from pattern-library/registry.json — do not edit by hand; change the registry and run bun run patterns:build.

Index card — the docs below are the canonical explanation; deep-tier pattern pages additionally carry invariants and emulation notes.

Category: PWA · Tier: light · Maturity: proven (verified 2026-10-10 @ 149f43a7-dirty) · Risk: medium — touches deploy config and can affect every installed client if misconfigured

The custom service worker precaches only the icons and the offline page's own assets (parsed from its HTML), fills the rest of the hashed build cache-first as it is used, serves HTML and __data.json network-only, never intercepts /api/* or SSE, and ships a kill switch that force-wipes caches and unregisters on a bad deploy.

When to use: Use when you need an installable offline shell without caching personalized HTML, plus a documented recovery path for a broken worker.

Avoid when

  • Unvisited routes must work fully offline — precaching only the offline shell leaves them to the offline page

Docs

Code

  • src/service-worker/index.ts — built on $app/manifest, $app/service-worker and $app/env (SvelteKit 3); its own tsconfig carries the WebWorker types (GitHub · GitLab)
  • src/lib/pwa/sw-policy.ts — offlineShellAssets: what install precaches (GitHub · GitLab)

Tests

Proof


Machine-readable record: pwa-service-worker in pattern-library/registry.json.

← Back to Pattern Library

Думаете, этот паттерн можно сделать лучше? Расскажите как.

Оставить отзыв