How to store your app's entire state in the url
11–20 of 416 posts
Re: How to store your app's entire state in the url
#12Re: How to store your app's entire state in the url
#13Re: How to store your app's entire state in the url
#14A 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.
That's really interesting. Do you have any idea how much data (i.e. max amount of json) you can store using something like that?
Re: How to store your app's entire state in the url
#15A 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.
Re: How to store your app's entire state in the url
#16Also, if you are careful you get undo and redo for free with the browser's back button doing all the work for you.
The disadvantages are that your representation of internal state becomes part of the interface - if you ever change your app you need to deal with versioning the state so your new version can transparently handle the old state format.
If your app has a server component that acts on this state, be super careful about acting on it and treat it as you would any other input under user control.
If you app is completely client side, consider storing the state in the #fragment section of the URL. This never gets sent to the server. An example from my own site [0] - see how the fragment part of the URL changes as you select different topics.
There are also limits on just how much you can cram into a URL but with care you can shove a lot of state.
Re: How to store your app's entire state in the url
#17The reason I did the compression (using pako as well) was that without it the URL was too long to show a preview on iMessage. I also compress the state manually myself which saved a bunch of bytes too.
Re: How to store your app's entire state in the url
#18Hey all, I made this post to show a technique that I'm using in my keyboard-centric flowchart editor [0]. I really love urls, and the power that they hold, and would love to see more apps implement little hacks like this. Also, another shout out to mermaidjs and flowchart.fun for also implementing similar url-based sharing. [0] https://www.knotend.com
There is a size limit though that quickly gets exhausted if you are storing text (2000 chars)
Re: How to store your app's entire state in the url
#19Hah, I came up with the same thing for https://fivethreeone.app/calculator . The reason I did the compression (using pako as well) was that without it the URL was too long to show a preview on iMessage. I also compress the state manually myself which saved a bunch of bytes too.
Re: How to store your app's entire state in the url
#20Hey all, I made this post to show a technique that I'm using in my keyboard-centric flowchart editor [0]. I really love urls, and the power that they hold, and would love to see more apps implement little hacks like this. Also, another shout out to mermaidjs and flowchart.fun for also implementing similar url-based sharing. [0] https://www.knotend.com
There is a size limit though that quickly gets exhausted if you are storing text (2000 chars)
Still on FF I opted to use LZ Compression (pretty sure many other sites do this as well) to get the number of characters down