Make Scratch an installable PWA #13

Merged
cmoriarty merged 1 commit from pwa-installable into main 2026-11-07 11:32:55 -05:00
Owner

What

Scratch is now an installable progressive web app: a home-screen icon, standalone (no browser chrome) display, and a cached app shell for instant loads.

Changes

  • Web manifest (packages/client/public/manifest.webmanifest): standalone display, portrait orientation, app name/description, theme + background colors, and icon entries. Linked from index.html.
  • App icon: a card with the brand heart on the felt, drawn as icons/icon.svg and rendered to icon-192.png / icon-512.png. The 512 also serves as the maskable icon — the card stays inside the maskable safe zone, so the same artwork works for both any and maskable purposes. apple-touch-icon.png (180) for iOS.
  • iOS meta tags: apple-touch-icon, apple-mobile-web-app-capable, apple-mobile-web-app-title, plus a description.
  • Service worker (packages/client/public/sw.js, registered in main.tsx in production only):
    • precaches the app shell (/, manifest, icons);
    • navigations are network-first so new deploys land on the next load, with the cached shell as the offline fallback;
    • same-origin assets are cached stale-while-revalidate (hashed files are immutable, so a cached copy is always correct).
    • Skipped in vite dev mode so it doesn't fight live reload.
  • Server: serve .webmanifest with application/manifest+json.
  • Tests (packages/client/src/pwa.test.ts): manifest is valid JSON with the installability fields and only references icons that exist; the service worker parses as a valid script and precaches the shell; the app shell links the manifest and apple touch icon.
  • README: an "Install as a PWA" note under Deploy.

Why this is the right scope

The game is real-time over WebSockets, so true offline play isn't possible. What a PWA genuinely gives us here is installability (home-screen icon, standalone mode — which also permanently avoids the short-viewport problem the browser chrome causes), plus an app shell that opens instantly and still loads when the network is down (the app shows its reconnect state rather than a blank page).

Verified

  • 160/160 tests, typecheck clean.
  • Service worker registers, activates and takes control; shell cache contains /, manifest, and both icons.
  • Offline check: with the server stopped, a reload renders the full landing screen from the service-worker cache (title, name field, avatar picker, create/join all present).
  • Manifest served as application/manifest+json; icons served with correct MIME.

Note: the bot pacing test in session.test.ts is timing-sensitive and flakes occasionally under load; it is unrelated to this change (no game/session code touched).

## What Scratch is now an installable progressive web app: a home-screen icon, standalone (no browser chrome) display, and a cached app shell for instant loads. ## Changes - **Web manifest** (`packages/client/public/manifest.webmanifest`): standalone display, portrait orientation, app name/description, theme + background colors, and icon entries. Linked from `index.html`. - **App icon**: a card with the brand heart on the felt, drawn as `icons/icon.svg` and rendered to `icon-192.png` / `icon-512.png`. The 512 also serves as the **maskable** icon — the card stays inside the maskable safe zone, so the same artwork works for both `any` and `maskable` purposes. `apple-touch-icon.png` (180) for iOS. - **iOS meta tags**: `apple-touch-icon`, `apple-mobile-web-app-capable`, `apple-mobile-web-app-title`, plus a `description`. - **Service worker** (`packages/client/public/sw.js`, registered in `main.tsx` in production only): - precaches the app shell (`/`, manifest, icons); - navigations are **network-first** so new deploys land on the next load, with the cached shell as the offline fallback; - same-origin assets are cached **stale-while-revalidate** (hashed files are immutable, so a cached copy is always correct). - Skipped in `vite` dev mode so it doesn't fight live reload. - **Server**: serve `.webmanifest` with `application/manifest+json`. - **Tests** (`packages/client/src/pwa.test.ts`): manifest is valid JSON with the installability fields and only references icons that exist; the service worker parses as a valid script and precaches the shell; the app shell links the manifest and apple touch icon. - **README**: an "Install as a PWA" note under Deploy. ## Why this is the right scope The game is real-time over WebSockets, so true offline *play* isn't possible. What a PWA genuinely gives us here is installability (home-screen icon, standalone mode — which also permanently avoids the short-viewport problem the browser chrome causes), plus an app shell that opens instantly and still loads when the network is down (the app shows its reconnect state rather than a blank page). ## Verified - 160/160 tests, typecheck clean. - Service worker registers, activates and takes control; shell cache contains `/`, manifest, and both icons. - **Offline check**: with the server stopped, a reload renders the full landing screen from the service-worker cache (title, name field, avatar picker, create/join all present). - Manifest served as `application/manifest+json`; icons served with correct MIME. Note: the `bot pacing` test in `session.test.ts` is timing-sensitive and flakes occasionally under load; it is unrelated to this change (no game/session code touched).
- Web manifest (standalone display, portrait, app icon) linked from the
  app shell, plus iOS meta tags (apple-touch-icon, web-app-capable).
- App icon: a card with the brand heart on the felt, drawn as SVG and
  rendered to 192/512 PNGs (512 doubles as the maskable icon; the card
  stays inside the maskable safe zone).
- Service worker (production only): precaches the app shell, serves
  navigations network-first with the cached shell as the offline
  fallback, and caches same-origin assets stale-while-revalidate. The
  app now opens instantly and still loads when the network is down
  (a game needs a connection, since it is real-time over WebSockets).
- Serve .webmanifest with application/manifest+json.
- Tests: manifest validity + icon existence, service worker syntax and
  shell precache, app shell links.
- README: how to install the PWA.
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
cmoriarty/scratch-vllm-fp8!13
No description provided.