Tutorials

Browser game saves: make progress survive the next visit

by

A player closes a tab after finishing a difficult level. The next day, the game opens at the beginning. Whatever caused the failure, the player has lost something they expected the game to remember. Saving deserves a place in a browser game's design early enough that returning to play is part of the test plan.

Start by deciding what must survive: settings, completed levels, the current run, or an entire collection of items. A short arcade game and a persistent world need different answers. Our look at Slime & Steel's browser MMORPG is a useful contrast when defining the scope of a smaller project.

Pick storage for the data you actually have

MDN's Web Storage documentation explains that localStorage persists across browser sessions, while sessionStorage is tied to a tab's session. Both use synchronous operations. For a modest settings object or a few completed-level flags, localStorage can be a reasonable starting point; repeatedly serializing a large world during gameplay is a different workload.

For larger structured saves, IndexedDB provides asynchronous operations and transactions. It can store objects and binary data, but it also asks you to design a database schema and handle the operation's eventual success or failure. Choose it because the data and write pattern benefit from it, not because every game needs a database abstraction.

Keep downloadable assets separate from player progress in your own data model. A texture can be fetched again; a player's only record of a completed challenge cannot be reconstructed that way. Give those categories different cleanup rules.

Treat saving as an operation that can fail

Do not show “Saved” merely because the player pressed a button. Show it after the write succeeds, and provide a useful message when it does not. For IndexedDB, account for transaction completion or abortion rather than treating an individual request as the final result.

Save at meaningful boundaries, such as completing a level or confirming an inventory change. Avoid relying entirely on the player closing the tab cleanly. Decide how much progress can reasonably be lost between checkpoints, then make that behavior consistent.

A compact replay, like the one discussed in our guide to putting a game replay in a URL, serves a different purpose from a full save. Write down which data reconstructs a run and which data records the player's wider progress so those responsibilities do not become tangled.

Local storage is not a backup

Browser storage normally uses best-effort retention. MDN's storage and eviction guide describes how quotas, storage pressure and browser policies can affect retained data. Users can also clear site data, and private-browsing data is usually removed when the private session ends.

The StorageManager persist method lets a site request persistent storage over HTTPS, but the browser can decline. Handle that result without preventing play. Even an accepted request does not protect against a user deleting their data or losing the device.

For games where progress matters over many sessions, consider a downloadable save export or an account-backed copy. An import should validate the file's shape, supported version and size before changing the current state. Let players cancel, and preserve their existing save when validation fails.

Plan for the next version of the game

Put a format version in the save from the beginning. When the game changes, migrate older data deliberately instead of assuming yesterday's object still matches today's code. Keep sample saves from released versions and load them during release checks.

Test two tabs too. If both can write the same save, decide how to detect or prevent an older session overwriting newer progress. Never silently replace an unreadable save with an empty one as the first recovery step; retain a copy and offer a clear reset choice.

The shared-world design discussed in our SpringTale article also points toward a separate decision: which results must be trusted by a server? Locally editable progress should not become unquestioned evidence for a competitive leaderboard.

Test the return journey

Try a fresh profile, a normal reload, a browser restart, a failed write, an old save and a corrupted import. Test the actual hosted or embedded version, because browser storage is associated with an origin and can be partitioned in embedded contexts.

Small finishing touches, like those explored in Songs of Hyrule, matter most when they support the player's expectations. A clear continue button, a truthful save indicator and a working recovery path make the next visit feel like a continuation of the last one.

Leave a Reply

Your email address will not be published. Required fields are marked *