wealth/docs/decisions/0051-cache-first-for-next-s...

1.2 KiB

0051 Cache first for /_next/static/, stale-while-revalidate for fonts and the sprite

Status: Accepted · Area: architecture · Date: 2026-10-09 · Decided by: user

Context

Adopted from kasra-pay's decision 0032. The pwa lib's worker served all four stored kinds stale-while-revalidate, so every served chunk started a background fetch. Next.js names each /_next/static/ file after its content, so that check can never find a change. Stale-while-revalidate exists to heal a file changed under its URL against the rules, which only fonts and the icon sprite can be.

Decision

  • The worker serves /_next/static/ JS and CSS cache first, with no network request on a hit, in both apps.
  • writeServiceWorker's strategy applies to fonts and the sprite only; its default stays 'stale-while-revalidate'.

Alternatives

  • Stale-while-revalidate for everything (the skill's default): one wasted background fetch per served chunk, and a real download when the HTTP cache dropped the file.
  • Cache first for everything: a font changed under its old name would never heal.

Consequences

  • Deviates from the skill's lib-pwa.md, which checks all four kinds.
  • pwa-assets-v1 keeps its version: stored entries stay valid.