Skip to content

Stop the service worker re-flooding GitHub Pages on every reload - #197

Merged
jiro-by-nori[bot] merged 1 commit into
mainfrom
fix/pages-reload-blocking
Nov 5, 2026
Merged

jiro-by-nori[bot] merged 1 commit into
mainfrom
fix/pages-reload-blocking

Conversation

@jiro-by-nori

@jiro-by-nori jiro-by-nori Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Summary

🤖 Generated with Nori

Root cause (verified on the live site): the production service worker precached all 24,918 files in public/ (≈150 MB; ~24.6k are per-sprite atlas-packer inputs the game never requests) in one atomic cache.addAll with cache: 'reload'. Pages/Fastly answered the burst with 503 (server: Varnish, retry-after: 0, HTML body). One non-OK response rejected addAll, the worker was discarded with nothing cached, and every reload / reopened tab started the whole ~25k-request download again. In a clean profile on https://opencoaster.noriagentic.com/ the page never became controlled across first visit, 3 reloads, hard reload and tab reopen; each load issued 3k–24k worker requests, 21k of them aborted after the 503.

  • tools/pwa/precache-urls.ts (used by vite.config.ts): precache only the bundle, shell and the public files the game requests (sprites/manifest.json, sprites/atlas/**, sprites/ui-icons/**; no CNAME). 24,918 → 278 URLs; worker script 1.68 MB → 12.6 KB. Offline play keeps every atlas page.
  • src/pwa/service-worker.js: install downloads ≤6 files at a time, stops at the first failure, and resumes a retried install from what this build's cache already holds. Activation/fetch strategy unchanged; IndexedDB/localStorage never touched. No client reload logic (no reload loop risk).
  • Docs: src/pwa/docs.md, docs/deploy/README.md, smoke/docs.md; corrected stale claims that UI icons are excluded from the atlas.

Test Plan

  • vitest src/pwa tools/pwa tools/sprites/dist-icons.test.ts: resumable install, bounded concurrency + cache: 'reload', precache selection (each failed first on main).
  • smoke/returning-visitor.spec.ts (production build under /opencoaster/, no COOP/COEP): returning visitor with an earlier build's cache, IndexedDB save and settings → worker controls with <1000 downloads, 3 reloads fetch only the navigation, old cache removed, save + settings intact, Load game lists the save. Fails on main's build (worker never controls within 60 s even on localhost).
  • Old-worker → new-deploy upgrade (local, real main-build worker installed first): new build installs with 280 downloads, then each reload = 1 download, 54/54 assets from worker, old cache gone, save intact.
  • lint, format, typecheck.
  • Note: returning-visitor.spec.ts only runs under pnpm smoke:subpath, which CI does not run; adding it to ci.yml needs the workflow scope.
  • Live verification after deploy (proof comment to follow).

Requested in Nori: https://demo.norisessions.com/chat/01a16c13-c814-7295-9955-b11ff875ed14

Share Nori with your team: https://www.npmjs.com/package/nori-skillsets

The production worker precached all 24,918 files in public/, most of them
per-sprite atlas packer inputs the game never requests, in one atomic
cache.addAll. GitHub Pages answered the burst with 503s, one failure
discarded the install, and every reload started the whole download again.

Precache only the bundle, shell and the public files the game requests
(sprite manifest, atlas pages, UI icons), download them a few at a time,
stop at the first failure and resume a retried install from what the
build's cache already holds.

Co-authored-by: Nori <contact@tilework.tech>
@jiro-by-nori
jiro-by-nori Bot merged commit 5b47730 into main Nov 5, 2026
1 check passed
jiro-by-nori Bot added a commit that referenced this pull request Nov 5, 2026
Co-authored-by: Nori <contact@tilework.tech>
@jiro-by-nori

jiro-by-nori Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Live proof (deploy run https://github.com/tilework-tech/opencoaster/actions/runs/41946045318, main @5b47730c)

Before (main @152523b0) After
Precache URLs / worker size 24,918 / 1.68 MB 278 / 12.6 KB
Install never finished; a Fastly 503 aborted ~21k requests, then it restarted on every load controlled after 7.1 s, 278 × 200
Each reload (×3), hard reload, reopened tab 3k–24k worker requests, never controlled 1 network request (shell), 56/56 assets from the worker, 0 console errors
Saved park n/a saved via the UI before the reloads; still listed afterwards and loads

The after run used the same session-Chrome profile the old worker had left behind (an ordinary returning visitor). It kept storage, and the stale cache was removed automatically.

loaded park after reloads

Traces, scripts and README: https://github.com/tilework-tech/opencoaster/tree/7d261aef1cc3d0a4079195798260efe8723b35fb/pr-197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants