Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most compact URL encoding of JSON data?

Some time ago I saw a website that encoded game replay data into unicode characters so that you could copy-and-paste the address to share it with friends. I basically want to do the same thing -- I've got some data in a JavaScript object and I want to put it into the address bar.

I know I can use jQuery.param or something like that, but I want a much more compact format.

Turns out this is a little tricky to Google. Most search results turn up URL shorteners, which is distinctly different. I am not trying to store a short URL in my database for later lookup. All the data should be in the URL itself.

What encoding can I use for this? A link or description of the algorithm is fine, but impementations for Node/JavaScript would be even better.

I only need to support the latest version of Chrome stable, so I don't care if older browsers can't handle the unicode. I think I'll put the data in the fragment portion (after #) so I only need to support whatever encoding rules apply to that piece. I think just about anything is allowed, no?

like image 254
mpen Avatar asked Jun 14 '17 19:06

mpen


1 Answers

There you go https://github.com/qntm/base65536 & https://www.npmjs.com/package/base65536

Base65536 is a binary encoding optimised for UTF-32-encoded text and Twitter. This JavaScript module, base65536, is the first implementation of this encoding.

It featured on hackernews some time ago.

like image 117
enapupe Avatar answered Oct 03 '22 04:10

enapupe