Top
Best
New

Posted by thm 11/2/2025

URLs are state containers(alfy.blog)
512 points | 213 commentspage 4
mk12345 11/2/2025|
I really like this approach, and think it should be used more!

In a previous experiment, I created a simple webpage which renders media stored in the URL. This way, it's able to store and render images, audio, and even simple webpages and games. URLs can get quite long, so can store quite a bit of data.

https://mkaandorp.github.io/hdd-of-babel/

WilcoKruijer 11/2/2025||
nuqs[0] is a great (React) library for managing state inside of the URL.

[0] https://nuqs.dev/

ahmadalfy 11/2/2025||
This is the first time I see this, thanks for sharing it
franky47 11/3/2025||
Thanks for mentioning it! (I'm the author)
SoftTalker 11/2/2025||
Modern browsers have an "open clean link" feature that strips all the query parameters (everything after the '?' character in the URL).

This is because many sites cram the URL full of tracking IDs, and people like to browse without that.

So if you are embedding state in your URL, you probably want to be sure that your application does something sane if the browser strips all of that out.

Ayesh 11/2/2025|
> Everything after the '?' character.

It only strips known tracking parameters b(like those utm_ query params). It does not remove all parameters; if that's the case, YouTube video links will stop working.

SoftTalker 11/2/2025||
Hm, I didn't know that. Seems very easy to game then, just change your tracking parameter name to one that the browser doesn't strip.
adolph 11/2/2025||
Hanselman famously said “URLs are UI” and he’s absolutely right

A challenge for this is that the URL is the most visible part of an HTTP request but there are many other submerged parts that are not available as UI yet are significant to the http response composition.

Additionally, aside from very basic protocol, domain, and path, the URL is a very not human friendly UI for composing the state.

nubinetwork 11/3/2025||
URLs are user supplied. You can't trust user data in 95% of cases. Storing stuff belongs in a database or a cookie.
jillesvangurp 11/3/2025|
That's true for any content or request coming from the user. If it's not signed by a trusted party, you should not trust it and instead validate whatever you receive. It doesn't matter whether a client side database, a cookie, a file, or indeed the url was used.

Urls are kind of convenient for a lot of things like form parameters, #link into an app or page, etc. That's state. Adding a bit more state via json in a parameter or whatever is about as old as the web is. Mostly, url length restrictions are still a bit of a problem but you need really long urls these days to hit those with most browsers. But aside from that, it's just another way to store stuff between requests.

llIIllIIllIIl 11/3/2025||
That’s the reason i stay away and keep my customers away from SPAs. Good ole html forms do the trick for 99.95% use cases.
andy_ppp 11/3/2025||
I think the set of rules around when to put things in the URL and when not to are incredibly complex and require serious thought. I don't want the whole history polluted with loads of entries either so when the replace the current history item and when to push a new one also requires a lot of discussion.
nonethewiser 11/2/2025||
>If you need to base64-encode a massive JSON object, the URL probably isn’t the right place for that state.

Why?

I get it if we're talking about a size that flirts with browser limitations. But other than that I see absolutely no problem with this. In fact it makes me think the author is actually underrating the use-case of URL's as state containers.

jarofgreen 11/2/2025||
Also to consider: bot traffic and SEO.

Depending on which mechanism you use to construct your state URLs they will see them as different pages, so you may end up with a lot of extra traffic and/or odd SEO side effects. For SEO at least there are clear directives you can set that help.

Not saying you shouldn't do this - just things to consider.

Ayesh 11/2/2025|
Canonical URLs come to the rescue.
jarofgreen 11/2/2025||
Only for SEO - they don't help at all with aggressive AI scraper bots.
due-rr 11/2/2025|
I use this for my rss reader!

https://rssrdr.com/?rss=raw.githubusercontent.com/Roald87/Ha...

More comments...