Fix PDFs still failing on browsers that used the old build #5

Merged
reudy merged 1 commit from sw-bypass-http-cache into main 2026-09-27 12:18:04 +02:00
Member

Problem. PDFs still failed to render on browsers that had used the app before #3. Firefox logged: "A ServiceWorker intercepted the request and encountered an unexpected error", then "Setting up fake worker failed".

Cause. Hashed files under /_app/immutable/ are served with Cache-Control: immutable, max-age=1 year. Before #3, the pdf.js worker was served as application/octet-stream, and the browser kept that response in its HTTP cache. Each new service worker filled its offline cache with addAll(ASSETS), which reads through the HTTP cache. So it copied the bad response again, and pdf.js loaded the worker from there. The worker's hash doesn't change between builds, so a rebuild didn't help.

Fix. The service worker now fetches each file with cache: 'reload' when it installs, so it always stores what the server currently sends.

Testing (Firefox with a persistent profile; the old build first, then the server upgraded):

  • Old → current main: the offline copy is still application/octet-stream and the PDF page shows "Could not display". This matches the user's diagnostics exactly.
  • Old → this branch: the offline copy is text/javascript and the PDF renders.
  • npm test: 24/24 pass. npm run check: 0 errors.

After deploying: git pull && docker compose up -d --build, then reload the app. The new service worker installs and replaces the bad copy. Reload again if the first reload still shows the error.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL

**Problem.** PDFs still failed to render on browsers that had used the app before #3. Firefox logged: "A ServiceWorker intercepted the request and encountered an unexpected error", then "Setting up fake worker failed". **Cause.** Hashed files under `/_app/immutable/` are served with `Cache-Control: immutable, max-age=1 year`. Before #3, the pdf.js worker was served as `application/octet-stream`, and the browser kept that response in its HTTP cache. Each new service worker filled its offline cache with `addAll(ASSETS)`, which reads through the HTTP cache. So it copied the bad response again, and pdf.js loaded the worker from there. The worker's hash doesn't change between builds, so a rebuild didn't help. **Fix.** The service worker now fetches each file with `cache: 'reload'` when it installs, so it always stores what the server currently sends. **Testing** (Firefox with a persistent profile; the old build first, then the server upgraded): - Old → current `main`: the offline copy is still `application/octet-stream` and the PDF page shows "Could not display". This matches the user's diagnostics exactly. - Old → this branch: the offline copy is `text/javascript` and the PDF renders. - `npm test`: 24/24 pass. `npm run check`: 0 errors. **After deploying:** `git pull && docker compose up -d --build`, then reload the app. The new service worker installs and replaces the bad copy. Reload again if the first reload still shows the error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL
agent added 1 commit 2026-09-27 12:17:33 +02:00
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
reudy merged commit 964b3b1cdd into main 2026-09-27 12:18:04 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/Papure#5
No description provided.