Make a browser game installable and playable offline (a progressive web app). A manifest template, a service worker that caches the game with versioned updates, a page helper that registers it only where it's safe (not in the Bash preview iframe or on shared portal hosts like itch.io), an Install button where the browser offers one, iPhone Add to Home Screen instructions, an "update ready" hook...
Download skill (.zip) Files on GitHubPWA game development
An installed web game opens from the home screen without the browser bar, runs fullscreen (even on iPhone), works offline, and keeps saves more reliably.
Where to use it
| Host | Service worker? |
|---|---|
| Your own site (GitHub Pages, Netlify, Cloudflare Pages) | Yes: this is where installing makes sense |
| Bash preview iframe | No (the helper skips iframes). Open the game in its own tab to test |
| itch.io, Newgrounds, CrazyGames, Game Jolt | No: many games share one origin; a worker there can break other games. Pass skipHosts: ["itch.zone"] |
The manifest and icons are harmless everywhere, so keep them in the build.
Setup
- Icons:
python3 scripts/make-icons.py art.png --out www/icons(--pixelfor pixel art) resizes the game’s own icon art into 192, 512, maskable 512, Apple 180 and a 32 px favicon. It doesn’t create art: the icon comes from the person. - Copy
assets/pwa/manifest.webmanifestandassets/pwa/sw.jsnext toindex.html. Fill the `` (orientation:landscape,portraitorany). Insw.js, list the files the game needs to start inPRECACHE. - In
index.html:<link rel="manifest" href="manifest.webmanifest"> <meta name="theme-color" content="#0b0f19"> <link rel="apple-touch-icon" href="icons/apple-touch-icon.png"> - In the game:
import { registerPwa, createInstallPrompt, installHelp, isStandalone, persistSaves } from "./pwa.js"; registerPwa({ skipHosts: ["itch.zone"], onUpdate: (apply) => notes.push({ text: "Update ready: tap to restart", action: apply }) }); const install = createInstallPrompt(); install.onAvailable((v) => (installButton.hidden = !v)); installButton.onclick = () => install.prompt(); no prompt (iPhone): show installHelp().text // "Tap Share, then Add to Home Screen" if (isStandalone()) persistSaves(); - Check:
python3 scripts/pwa-check.py www --url http://localhost:8080/(files, icons, precache list, then a browser run: worker active, page controlled, loads with the network off). 2D games only in the sandbox browser; for WebGL games run it without--url.
Updates
Change VERSION in sw.js on every release. Players get the new files in the background; onUpdate lets them restart
into the new version (never reload mid-game without asking). Old caches are deleted on activate. Forgetting the version bump
means players keep the old game until the cache changes.
Notes
- HTTPS is required (localhost is allowed for testing).
- The worker caches same-origin GET requests only: APIs, leaderboards and multiplayer always go to the network.
- Large optional files (music for later levels) are cached the first time they load instead of at install.
- Installed iPhone apps get their own storage, separate from Safari: saves don’t carry over between the two.
Tested
Node tests for the page helper: skipping iframes, non-HTTPS pages, missing support and named hosts; registering and offering a
waiting update; the install prompt flow; installed detection; asking for persistent storage. The device lab (cross-browser-
compatibility) uses these files: pwa-check.py passed on it with the worker active, the page controlled and an offline reload
working in Chromium.
Pitfalls
Registering a worker on a shared portal host, forgetting the version bump, precaching a file that doesn’t exist (install fails silently), caching API responses, no icon sizes, and reloading the page during play for an update.