DEV Community

Qiang Li
Qiang Li

Posted on Edited on

How We Built Zero-Server Couples Overlap Rooms Using URL #hash Fragments

When we built Purity Test Lab, we made one strict architectural constraint from day one: no backend database and no API endpoint for user answers.

That is straightforward when a single visitor takes the 100-question Rice Purity Test in their own browser. Everything lives in memory (plus optional tab-scoped sessionStorage for refresh recovery).

Things get much trickier the moment users ask for multiplayer features:

  • "Can my partner and I compare answers and see only what we both checked?"
  • "Can our friend group build a shared leaderboard without creating accounts?"

Here is how we built Couples & Group Rooms with zero server storage by packing state into URL #hash fragments.

Why #hash Fragments?

Unlike query parameters (?data=...), the fragment identifier after # is never sent by browsers in HTTP requests to the origin server or CDN logs. By hosting a static Next.js export on Cloudflare Pages and keeping all comparison state after #, the server only ever sees GET /rooms/.

Packing 100 Checkboxes Into 13 Bytes

For Couples Overlap, storing an array of up to 100 integers in JSON and Base64-encoding it would bloat URLs—especially on mobile messaging apps.

Instead, we pack answers into a compact bitmask:

export function encodeYesIdsToBitmap(
  yesIds: number[],
  questions: CanonicalQuestion[]
): string {
  const yesSet = new Set(yesIds);
  const byteCount = Math.ceil(questions.length / 8); // 13 bytes for 100 items
  const bytes = new Uint8Array(byteCount);
  questions.forEach((q, idx) => {
    if (yesSet.has(q.id)) {
      bytes[Math.floor(idx / 8)] |= 1 << (idx % 8);
    }
  });
  return bytesToBase64Url(bytes);
}
Enter fullscreen mode Exit fullscreen mode

That 13-byte bitmap is wrapped in a tiny versioned JSON object—{ v: 1, n, s, b }—and encoded as URL-safe Base64 (+ → -, / → _, stripping trailing =) under #couples=.... Even with a display name, the full invite URL stays short enough to paste cleanly into iMessage, WhatsApp, or Discord.

Computing the Overlap Locally

When the partner opens the invite link:

  1. The browser parses window.location.hash, validates the v: 1 schema, and decodes the bitmap into a Set<number> of checked question IDs.
  2. They complete their own checklist locally in the browser.
  3. Both sets are intersected client-side to render only shared experiences, category overlap counts, and a dual-series 5-dimension radar chart.

For Group Leaderboards (#group=...), we avoid sharing individual answers altogether—each entry only encodes { n, p, s } (nickname, 0–100 score, and a 1-character edition code) for up to 15 members.

Honest Security Framing

URL-hash storage prevents server-side logging, not client-side inspection by someone holding the invite URL:

  • A Couples Overlap invite carries the sender's bitmap in encoded, not encrypted form.
  • Messaging apps that preview links or store chat history also see the URL.

Rather than overselling it as "zero-knowledge cryptography," our UI displays an explicit confirmation checkbox before generating a link so users only share Couples invites with someone they trust.


If you want to try the implementation live, check out Rooms on Purity Test Lab or browse the full 100-question reference guide.

Top comments (0)