Menu

URL as a database: custom word decks without login
📰

URL as a database: custom word decks without login

DEV Community: security·no momo·3 days ago
#XcbwU5na
#devtosecurity#devto#dev#words#string
Long article (457 words) — no AI summary yet.
Reading 0:00
15s threshold

/custom lets users enter 10–30 words and generate a link. Someone else opens the link and plays the same set. No login. So the question is: where do those 30 words live?

The lightest option is URL fragment encoding:

// encode const payload = JSON . stringify ( words ) ; const encoded = compressToEncodedURIComponent ( payload ) ; // lz-string const url = `${location.origin}/custom#${encoded}` ;

// decode (after hydration) const raw = location . hash . slice ( 1 ) ; if ( raw ) { const words = JSON . parse ( decompressFromEncodedURIComponent ( raw ) ) ; validate ( words ) ; // required: 10–30 items, per-word length cap, strip control chars }

Enter fullscreen mode

Exit fullscreen mode

I use the fragment, not the query string, because fragments never leave the browser — the word set stays invisible to the server. lz-string 's compressToEncodedURIComponent outputs URL-safe characters, no extra escaping needed.

The real cost of this approach : 30 words compressed is still a few hundred characters.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.