Adding a service worker to an essay platform improves plane and commuter reading instantly, yet blanket caching breaks cache-control invariants when dynamic /brief/[id] snapshots or /api/* endpoints coexist on the same origin.
Explicit fail-closed bypass rules alongside worker-src 'self'#
In v6.0.0, public/sw.js ships with strict scoping rules verified against next.config.js:
- Private route immunity: Requests under
/api/and/brief/(plus/{en,zh}/brief/) return directly to the browser network stack—never touched by Cache Storage. - No-cache worker updates:
next.config.jspairsworker-src 'self'CSP withCache-Control: no-cache, no-store, must-revalidateon/sw.jsso stale workers rotate reliably. - Network-first reading shell: public EN/ZH case pages and the 30 essays serve the last-visited HTML copy when connectivity drops, and immutable
/_next/static/assets use stale-while-revalidate.