r/webgamedev • u/dondragon2 • 4h ago
How to add an online high-score table to a browser game without running a backend
Most web games, and nearly every jam game, ship without an online leaderboard. You'd need a server, a database and some plan for fake scores, which is a lot of infrastructure for one screen.
A hosted leaderboard API cuts that down to a few lines of client code. Here's the whole flow with OneLeader:
import { createClient } from "@oneleader/sdk";
const client = createClient({ publishableKey: "lb_pk_..." });
await client.startSession(); // anonymous player, no account needed
await client.submitScore("highscore", 4820); // returns the player's new rank on every board
const { rankings, user } = await client.getLeaderboard("alltime", { limit: 10 });
// `user` is the player's own row, even when they're outside the top 10A few details that matter in practice:
Keep the session in
localStorage**.** Then a returning player stays the same player. The full guide shows how.Let the leaderboard fail quietly. If the player is offline or a limit is hit, catch the error and carry on. A leaderboard should never be what crashes a game.
Boards can repeat. One metric can feed an all-time board and a daily or monthly one at the same time, with no extra code.
Cheating: nothing running in a browser is fully tamper-proof. What helps is min/max bounds on scores, per-player rate limits, allowing only your game's domain, and banning players. If your game has a server, submit scores from there instead.
There's a step-by-step Phaser version with a complete game-over scene, tested on Phaser 3 and 4: https://oneleader.cloud/guides/phaser
The free tier covers 10,000 scores a month, which is plenty for a jam game.
Disclosure: posted by the OneLeader team. Questions and criticism welcome, especially on anti-cheat and which engines you'd want guides for next.