ARTICLE

Building an Offline-First Scorekeeper: IndexedDB, a Service Worker and No Backend

How a Hazari scorekeeper works with no connection: IndexedDB for games, a service worker for the app, validated backups and a deliberately small first download.

Tags

  • PWA
  • Offline First
  • IndexedDB
  • Dexie
  • React
  • TypeScript

Published November 24, 2026.

A card game scorekeeper has a hostile environment. It runs on a phone at a table, often on a poor connection, and it must never lose a score. That pushed the design toward one rule: scoring must never wait for a network.

Games live on the device

Saved games, rounds and recent player names are stored in the browser's IndexedDB through Dexie. There is no server for scoring and no account. The data layer is a small set of repository functions, and screens read through hooks and change data only through those functions, so storage can change without touching the interface.

A service worker keeps the app itself offline

A service worker caches the application shell, so it reloads with no connection after the first visit. The public guide pages are cached too, so they also work offline. A new version waits for the user to accept it, and it will not replace the app while a score draft is open.

Pure rules, separate from the screen

The scoring rules are a pure TypeScript module with its own unit tests. It knows nothing about React or IndexedDB. An architecture check in the build enforces this, so the domain code cannot import from the data or interface layers.

Validated backups

Players can export their games to a file and import them later. Anything that comes back in from a backup or a shared link is validated with Zod before it touches the database, so a damaged or hand-edited file cannot corrupt saved games.

Keeping the first download small

The app shell is about 98 KiB when compressed, under the 110 KiB limit I set for it. Anything heavy, such as the cloud sharing code and the QR generator, is loaded only when needed and is excluded from the first download and the offline cache. If those optional pieces fail to load, local scoring still works.

Privacy by construction

Game data stays on the device unless the user starts sharing. The site uses only basic pageview analytics, loaded in production only, with game links grouped and query strings removed. Names and scores are never sent, and there are no custom events.

Settings includes a Clear device data option that asks for confirmation, offers an export first, and removes games, rounds and recent names together. The shared links that the device owned are closed separately, so clearing while offline cannot leave an old link alive.

How it is tested

Unit tests cover the rules. Browser tests cover the main flows at a 360 × 640 phone size, including offline use, five players, Bangla, and accessibility checks in light and dark themes.

The overview of the whole app is in How I built an offline Hazari scoring app. The live scoreboard design is the one part that does use a server.

Play it or score it

Play Hazari alone against the computer, or keep score and share the banter with your friends. It is free and works offline.

More Hazari guides

All Hazari guides

Odds and numbers

Strategy

Scoring and house rules

Playing with friends

Behind the app