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
Odds and numbers
- How Rare Is a Troy? The Odds of Every Three-Card Hand in Hazari
- Why Every Hazari Deal Is Worth Exactly 360 Points
- How Many Deals Does a Game of Hazari to 1,000 Take?
- 200,200 Ways to Arrange 13 Cards: Why Hazari Is Harder Than It Looks
Strategy
- How to Arrange Your Cards in Hazari: A Practical Guide to 3-3-3-4
- The Four-Card Group in Hazari: Weakest by Rule, Biggest Prize in the Deal
- 7 Mistakes New Hazari Players Make When Arranging Cards
- One Hazari Deal, Round by Round: A Worked Example with Real Cards
Scoring and house rules
- Scoring Hazari Round by Round: One Full Game to 1,000, Worked Through
- How to Settle a Hazari Scoring Argument in Two Minutes
- Hazari House Rules Checklist: Agree These 8 Things Before the First Deal
- Paper or App? How to Keep Hazari Score Without Arguments
Playing with friends
- Roasting Your Friends at the Hazari Table: Funny Leaderboard Tags
- Let Friends Watch Your Hazari Game Live: How to Share a Scoreboard
- Play Hazari Alone: Practise Against Three Computer Players
Behind the app
- How I Built an Offline Hazari Scoring App Friends Can Watch Live
- How the Hazari Computer Opponent Chooses Its Cards
- Designing a Read-Only Live Scoreboard With Guest Sharing
- টেক্কা, সাহেব, বিবি, গোলাম: Making a Card Game App Natural in Bangla
- Making a React App Findable: Real HTML Pages Before JavaScript Runs