For a browser game, use the Web Storage API (localStorage) for small key-value saves or IndexedDB for larger structured data. If the game runs on multiple platforms, route saves through a storage abstraction so the same code can write to a platform’s cloud save instead of only the browser.
At a glance
| Fact | Value | Source |
|---|---|---|
| Simple key-value saves | localStorage | developer.mozilla.org |
| Unity WebGL calls browser JS via | .jslib plugin | docs.unity3d.com |
| Godot 4 web calls browser JS via | JavaScriptBridge singleton | docs.godotengine.org |
For a plain HTML5/JS game, the Web Storage API (localStorage) is the simplest way to persist progress: it stores string key-value pairs synchronously and survives page reloads. For larger or structured data (inventories, level layouts, replay data) use IndexedDB instead, since it handles bigger payloads and complex objects without you having to serialize everything into strings yourself.
If your game is meant to run across several platforms and portals, don’t write saves straight to localStorage or your engine’s own local persistence. A storage abstraction layer picks the right place to store data per platform, including cloud saves where available, so progress follows the player instead of staying stuck in one browser. For multi-platform games, the Playgama Bridge SDK provides a Storage module that handles saves automatically across platforms.
How do engines call browser storage?
- Unity WebGL builds reach browser JavaScript through a
.jslibplugin placed in the project. - Godot 4 web exports use the
JavaScriptBridgesingleton (calledJavaScriptin Godot 3). - Other engines that export to web (Construct 3, GDevelop, Defold, Cocos Creator, GameMaker, PlayCanvas) expose similar bridges or plugins to call storage APIs.
Handle missing data gracefully: treat an empty or null result as “no save yet” and load sane defaults rather than treating it as an error – there is no dedicated error event for a failed read, so check the returned value.
Sources
- MDN: Web Storage API
- Unity manual: interacting with browser scripting
- Godot docs: exporting for the Web
- Playgama wiki: Storage
- Playgama Bridge getting started
Related questions
Should I use localStorage or IndexedDB for game saves?
localStorage is fine for small key-value data like settings or a single save slot. IndexedDB suits larger or structured data such as multiple save slots, inventories or logs.
What happens if a save key doesn’t exist yet?
Missing keys return null, so keep defaults instead of failing.
Last updated: 24 September 2026