Fix PDFs still failing on browsers that used the old build #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "sw-bypass-http-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 withCache-Control: immutable, max-age=1 year. Before #3, the pdf.js worker was served asapplication/octet-stream, and the browser kept that response in its HTTP cache. Each new service worker filled its offline cache withaddAll(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):
main: the offline copy is stillapplication/octet-streamand the PDF page shows "Could not display". This matches the user's diagnostics exactly.text/javascriptand 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