Skip to content

Players get updates straight away (fresh files and a quick switch) - #41

Merged
maidulcu merged 1 commit into
mainfrom
fix/sw-fresh-files
Nov 10, 2026
Merged

maidulcu merged 1 commit into
mainfrom
fix/sw-fresh-files

Conversation

@maidulcu

Copy link
Copy Markdown
Contributor

After an update, players' first visit still ran the old version of the game. The service worker serves the saved copy first and only downloads the new one in the background, and the new one only started on the next visit. So the insights and the iPhone Bit fix from #40 reached nobody on their first visit.

Changes

  • Switch to the new version straight away when nothing would be lost. When a new version takes over (controllerchange) and the player is still on the start menu, with no panel open and not typing, the page reloads into it. Otherwise a toast says "A new version of MiniCrafter is ready. It loads next time you open the game." First visits (no earlier version) never reload.
  • Never store the browser's old files. The service worker installs with cache: 'reload' and refreshes with cache: 'no-cache'. Our server lets browsers keep .js files for 4 hours, and without this the offline copy could pick up those old files. I couldn't reproduce that in Chrome, so this is a safeguard; revalidating costs only a small "not changed" reply.
  • sw.js → minicrafter-v30.

Testing

  • Update test: a local server sends the same 4-hour cache headers as the live site, then switches to a new version while the page is open. The page loaded the old version, the new one took over, and the page reloaded itself into it (load 3 in the log). The new cache had the new files.
  • SMOKE_CHANNEL=chrome node tests/smoke.mjs: all checks pass, including the offline reload.
  • Deployed to the online edition: sw.js is minicrafter-v30.

Players who already have v29 run code without the auto-switch, so they get v30 on their next visit and the quick switch from then on.

🤖 Generated with Claude Code

After an update, the saved copy of the game started first, so a player's first
visit still ran the old version (no insights, and still the iPhone Bit freeze).

- When the new version takes over while the player is still on the start menu
  with no panel open, the page reloads into it. Otherwise a toast says it loads
  next time, so nothing in progress is lost.
- The service worker fetches files with cache: 'reload' when installing and
  'no-cache' when refreshing, so it never stores the browser's old copies
  (our server lets browsers keep files for 4 hours).
- sw.js -> v30.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maidulcu
maidulcu merged commit 983f2ee into main Nov 10, 2026
1 check passed
@maidulcu
maidulcu deleted the fix/sw-fresh-files branch November 10, 2026 13:54
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.

2 participants