Skip to content

Service Worker

Marco Supino edited this page Aug 4, 2026 · 5 revisions

🇮🇱 עברית

Service worker

docs/sw.js owns two deliberately separate caches:

  • CACHE (navaid-<build>) — app shell, same-origin assets, and pinned CDN runtime libraries.
  • TILE_CACHE (navaid-tiles-v1) — chart packs populated explicitly by docs/app/offline-tiles.js.

During activation, obsolete app caches are deleted but TILE_CACHE is always preserved. Do not replace this with “delete every cache except CACHE”; that would erase large user-downloaded chart packs on each app update.

HTML navigations are network-first and cache only successful responses, with an app-shell fallback offline. Versioned assets are cache-first; a successful miss is stored and older query-version siblings are pruned.

Chart-tile requests use the service worker only after tilePackReady confirms that the dedicated pack cache exists. Hits come from the pack; misses go to the network and are not passively cached. A tile-pack-changed message refreshes the flag and cached handle after download/delete.

Deploy rewrites the app-cache name and ?v= markers to the short SHA. The tile cache name remains stable so offline packs survive deploys.

Clone this wiki locally