The ?code= URL, Part Two: What URL-Encoded Code Can't Do

The ?code= URL, Part Two: What URL-Encoded Code Can't Do

●2 ●13 ●43
calendar_today ago • schedule3 min read
— Originally published at nitroide.com

In part one I showed how NitroIDE shares a whole workspace in a link: the three files and the CDN list get JSON-stringified, compressed with LZ-string, and stuffed into a ?code= query parameter. No server, no database, no account — the URL is the database. Readers liked it. Several asked the obvious follow-up: what breaks? A URL is a terrible database, and I measured exactly where it stops working.

Here are the limits, with numbers I ran against the real code — not guesses.

LZ-string is a dictionary compressor. It earns its keep on repetition and pays overhead on everything else. The dictionary itself costs characters, so for small payloads the "compressed" output is bigger than the input.

I measured it with the site's own vendored copy of lz-string. A small demo workspace — 367 bytes of JSON across three files — compresses to 417 characters. Ratio: 0.88x. The link got longer. If you share a ten-line snippet, the compression is pure overhead; the raw code would have been shorter in the URL than the compressed version.

Flip the input and the same code looks like magic. A 200KB workspace of repetitive markup compresses to 1,913 characters — 104x. And high-entropy content goes the other way: 20KB of random-ish text comes out at 28,676 characters, about 40% bigger than the raw JSON. Minified blobs, base64 data, long random strings — the things that look most like "data" are the worst case for this scheme.

The shape of your code decides whether the link shrinks or grows, and you never see that decision happen. The Share button doesn't warn you.

Limit 2: nothing checks the length

There is no length guard in the share path. buildShareUrl takes the JSON, compresses it, and concatenates the URL. A varied, realistic project — about 3,000 short statements of JavaScript — produces a 17,587-character URL, and nothing anywhere says "that's too long."

Your browser will happily accept it. The middle of the internet will not. Proxies, CDNs and chat apps commonly cap or truncate request lines around 8KB — far below what a browser tolerates. The link works on your machine, in your browser, and then dies somewhere between you and the person you sent it to.

This is the one that actually costs people work. Here is the entire decode path, in the site's real code:

sharedCode = urlParams.get("code");
if (sharedCode && typeof LZString !== "undefined") try {
  const e = LZString.decompressFromEncodedURIComponent(sharedCode);
  const t = JSON.parse(e);
  // ... restore workspace, then strip ?code= from the address bar
} catch (e) {
  console.error("Failed to parse shared link.");
}

A truncated payload decompresses to null, JSON.parse throws, and the catch swallows it. I verified this: a 17,587-character payload cut to 2,000 characters fails exactly this way. What the recipient sees is the default empty workspace — indistinguishable from opening the IDE fresh. No error toast, no "this link is broken" state. Your recipient assumes you sent them an empty project.

There is a second silent failure hiding in the same function. The payload has no version field — it is exactly {vfs, activeFiles, cdnLinks}. If the format ever changes, old links have no way to be detected as old. They just stop parsing, and the catch swallows that too.

The one trap that is already defused

The encoding itself looks like it should break. The LZ-string URI-safe alphabet includes +, and in a query string + means space. In 200 sample payloads I generated, 62 contained a + — so this is not a corner case, it is a third of all links. And URLSearchParams does exactly what you'd fear: the round-trip is not identical, the + comes back as a space.

But the decode still works, because the library anticipates the mangling: decompressFromEncodedURIComponent opens with r.replace(/ /g, "+"), converting spaces back before it decompresses. Double percent-encoding round-trips fine too — I verified that as well. The one encoding trap everyone expects is the one that's already handled. Credit to the library, not to me.

What to do instead

For a workspace too big for a URL, the codebase already has the escape hatch: ?gist=<id> and ?url=<raw-url> imports fetch the code from GitHub Gist or any raw URL instead of carrying it in the address bar. Same zero-backend philosophy, different transport — the URL becomes a pointer again instead of the whole database. And for embeds, ?embed=1&code= keeps the same payload but drops the IDE chrome, so the link at least fails small.

The honest summary: the ?code= link is brilliant for demos, snippets, and the "try this" moment — small, repetitive, human-written code compresses beautifully and opens instantly. It is the wrong transport for a real project. The failure isn't loud, and that's the problem: a share link should either carry your code or tell you it can't. Right now it does neither — it just opens an empty editor and lets you assume the worst about your own work.

I build NitroIDE — a browser-based IDE where your code never leaves your machine: https://nitroide.com?utm_source=coderlegion&utm_medium=article&utm_campaign=daily-2026-11-26

Want more #webdev & #opensource deep dives?

Join 6,047+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

Cloudflare Blocked My Server, So I Made My Visitors' Browsers Do the Fetching

bryanhamiltondevverified - Nov 15

StarlingX 13.0 Turns Two Edge Upgrades Into One Reboot. Test the Targets Yourself.

Tom Smithverified - Nov 24

The Sovereign Vault — A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

Short links that outlive the vendor: a newsroom URL shortener on WordPress and AWS

jaafarabazid - Nov 10
chevron_left
779 Points • 58 Badges
India • nitroide.com
23Posts
7Comments
5Connections
I’m a full-stack developer passionate about developer experience, performance, and modern web engine... Show more

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!