Bypass the HTTP cache when the service worker caches assets

Hashed assets are served as immutable for a year. Before the nginx MIME
fix, the pdf.js worker was served as application/octet-stream, and the
browser kept that response. Each new service worker then copied it from
the HTTP cache into its offline cache, so PDFs still failed to render
after the server was fixed. Fetching with cache: 'reload' always takes
the current response from the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL
This commit is contained in:
agent 2026-09-27 10:17:21 +00:00
parent cb4d3bfc79
commit 01624c6efa

View file

@ -16,7 +16,9 @@ sw.addEventListener('install', (event) => {
event.waitUntil(
caches
.open(CACHE)
.then((c) => c.addAll(ASSETS))
// Bypass the HTTP cache: hashed assets are cached as immutable, so a bad
// response (e.g. a wrong MIME type) would otherwise be copied in forever.
.then((c) => c.addAll(ASSETS.map((url) => new Request(url, { cache: 'reload' }))))
.then(() => sw.skipWaiting())
);
});