Live data from Hacker News

How to store your app's entire state in the url

scottantipa.com

141–150 of 416 posts

Re: How to store your app's entire state in the url

#141

A better idea is to use the URI fragment (the string after the # sign). It has the advantage of not having a size limit, and not needing to be sent all to the backend during the request. `window.location.hash` is your friend.

If you have so many parameters that you need a URL that's over 2048 characters, you should probably be reminded that localStorage exists.

Re: How to store your app's entire state in the url

#142
We are testing this on a map[0], it's fun. When tweeting the link, the tweet and its state is added to the map. Also, map stories are possible through Twitter threads. We just implemented a draw function and are working on an implementation for external geojsons.

[0] https://map.decarbnow.space

Re: How to store your app's entire state in the url

#144
I did something similar in a simple whiteboarding app that I made a while back:

https://github.com/jncraton/box-line-text

The data representation could probably improve in terms of readability, but I'm happy with the way it provides a concise encoding while still including the text from the document directly:

https://box-line-text.netlify.app/#;c2121Hello;5321;c1341Hac...!

Re: How to store your app's entire state in the url

#145

Earlier quoted context omitted.

The possible advantage of the encoding is that it that it can be encrypted and make parameter hacking impossible.

Harder. Not impossible. Harder. I don't want to make it sound like I am being disagreeable just for the sake of being disagreeable. If there is one thing the past decade has shown, it is that hacking is just a matter of time and whether a determined person is willing to direct resources at it.

I see you, and raise you:

What if they encrypted the parameters with a one-time pad ?

Re: How to store your app's entire state in the url

#147

Earlier quoted context omitted.

I did once and was told off for adding noise to the discussion by someone who didn't see the irony of their complaint also adding to the noise.

If a one-time correction has its desired impact, the small addition to the noise reduces future noise.

This is some sort of meta joke, right?

Re: How to store your app's entire state in the url

#148

Earlier quoted context omitted.

you could come up with a better compression scheme given that the dict keys and many of the values are probably common across everyone even if they don't repeat multiple times for a given user. a lot of flexibility would be lost though, and you would need to always update the scheme in a backwards-compatible way.

Once you've already given up on human-readability, it probably doesn't much matter how long/gross the result is. Rather than spending effort and adding complexity, just provide a built in URL shortener.

I agree, same reason people use json in the first place despite the inefficiency, it's easier.

Re: How to store your app's entire state in the url

#149

I remember when WebSphere Portal Server used to do this, and the URL would exceed 4096 characters, which was the limit that IE 6 (?) would support, breaking the entire site.

There is still a browser URL limit, I have hit it recently while applying a large number of filters to a search in Kibana.
Post reply on HN