How a web game keeps playing with no connection
Momiji Go is a web page, yet once you have opened it online it plays on a train, on a plane or in a garden with no signal: Lord Tsukikage, the lessons, the music and all. Here is how the page keeps a copy of itself on your device, why that copy is always exactly one version of the game, and the mistake that once made a first visit download everything twice.
Why a Go game can work offline at all
Most online games need a server for every move. Momiji Go does not: Lord Tsukikage thinks on your own device, in the browser, and the music is composed there as you play. Everything a game against him needs is files: the page, its code, the garden's models, the textures, the sounds and the lettering. If those files are on your device, the game has everything it needs.
The tool for that is a service worker, a small script that a web page can install in the browser. It sits between the page and the network, and it can answer the page's requests from a store of files of its own. Once it holds every file the game needs, a reload downloads nothing, and a visit with no connection still plays.
Always exactly one version
The dangerous thing about a copy is a copy that is half old and half new: yesterday's code with today's models, say. That kind of mixture breaks in ways that are hard to reproduce, and players are the ones who find them. So each build of Momiji Go writes a list of every file the game needs, each with a fingerprint of its contents (a SHA-256 hash). Nothing else decides what is kept. A copy on your device is always one release, whole, and never a mixture of two.
Every file is checked against its fingerprint before it is kept. If a network cache somewhere hands over an out-of-date file, the check fails, the new version is not installed, and it is tried again on your next visit, while the old version goes on working.
Downloading as little as possible
When a new version comes out, the fingerprints make updates small. A file whose fingerprint matches one already kept from the last version is copied across on your device, not downloaded again. Most of the garden does not change from one version to the next, so most of an update never touches the network.
Some files only some players need. The lettering for Japanese, Chinese and Korean is drawn from large font images, and a player who reads only one of those languages should not have to download all of them. Those files are kept the first time the page asks for them, and not before. A Japanese player's copy has the Japanese lettering; nobody downloads four languages to play in one. In version 1.0.2, the copy is about 14 MB, plus the lettering of your language.
The mistake: everything twice
At first, the page installed its service worker as soon as it started. The worker then began to fetch every file of the game while the page was still fetching the same files for itself, so a first visit downloaded the whole game twice. On a fast connection nobody noticed. On a slow phone, the doubled wait ran past the end of the opening splash, and the player was left looking at a black page.
Now the copy is made only once the garden is on screen. By then, the browser has just downloaded almost every file to show it, and the worker takes each one from the browser's own cache, as long as its fingerprint matches. A first visit downloads each file once; the copy is made from bytes that are already on the device.
Updates never land in the middle of a game
The browser checks for a new version on every visit, and installs it beside the old one, quietly. What it does next depends on what you are doing:
- if you are still on the opening scene and nothing has started, the page moves to the new version at once, reloading from the copy on your device in about the time a splash takes;
- if a game, a lesson or a match with a friend is under way, nothing changes until you next open the game. A game in progress never has its files swapped underneath it.
Hands and controllers, offline too
One kind of file is not ours. In VR, the 3D models of your controllers and hands come from a public library of models, fetched from a content delivery network the first time a controller or a hand appears. Which ones a player needs is only known then, because it depends on the headset.
So the worker keeps each model the first time it is fetched, in a store of its own that outlives every version of the game. It also keeps the ones the same headset is likely to want next: the controller's other hand, and both hands. A player who has only ever used controllers can put them down offline and play with their hands. The network is asked once per device.
What still needs a connection
Playing another person online needs a connection, because the moves go from one device to the other. So does counting visits to the page, which we do without cookies. Everything else, playing Lord Tsukikage at any of the seven levels, the twelve lessons and the music, works offline once the game has been opened online on that device.
To try it, open the game at its own address, momijigo.bruna.world, where it keeps its copy, and wait for the garden. Then switch on airplane mode and reload. If you would like to know how the opponent thinks without a server, read How Lord Tsukikage plays Go at seven strengths.

