let X, B, O, m, i, c, e, N, M, o, t, j, x, R;
and doesn't get any more readable from there. (And that's the unminified version!)There aren't any tests, either, so if you're using this and find a bug I guess you just have to hope that nothing breaks when you change a line like
for(M=N=e=c=0,i=Q.length;!c&&--i;)!~s.indexOf(Q[i])&&(c=Q[i]);https://nikhilism.com/post/2012/demystifying-jscrush
If you go to the live demo, it will do a test to crush/encodeURI and uncrush/decodeURI to the string you pass in and verify that they are the same. Maybe I should write some automated tests.
Thanks again!
Example #1 (short string):
input: 103 bytes
gzip(input): 87 bytes
base64(gzip(input)): 117 bytes
Example #2 (long string): input: 3122 bytes
gzip(input): 840 bytes
base64(gzip(input)): 1121 bytes...
https://donohoe.dev/project/jspng-encoder/
Life is too short to do something useful so why not encode all your site's Javascript code into a PNG image and then decode it on demand.
(This is a terrible idea. Don’t do it. Just for fun)
Why is this a terrible idea?
I'm thinking I can Whatsapp friends a huge letter as an image and they could use my toy app to decode it ;-)
for(M=N=e=c=0,i=Q.length;!c &&--i;)!~s.indexOf(Q[i])&&(c=Q[i]);
RegExp(`${(g[2]?g[2]:'')+g[0]}|${(g[3]?g[3]:'')+g[1]}`,'g');
(Though it's mostly meant for making things smoother in statically-typed languages.)
But when you put json in the URL, you normally do want exactly that. Making the URL shareable.
I do that because I wanted users to be able to save their state without burdening those users with accounts or burdening myself with maintaining a DB for something so simple.
I also somewhat abuse the history API and use my "read the URL and load state" logic to implement undo-redo via navigating back and forth, though that doesn't seem to work right now. I am working on a refactor that uses redux to implement undo-redo and just replace state, to keep the user's history clean.
Storing encoded JSON in the URL hash is a nifty hack in my opinion. Users can save state in a bookmark or share it with others easily, and it's clear to the users that "where they are" in the URL bar maps to the current app state. Plus, bookmark syncing is taken care of by most browsers to make that state available elsewhere, etc. For the site owner, it means not needing a DB to make an app with some kind of state persistence.
One risk: be sure the state you persist to the URL is in a schema you plan to retain compatibility with! Blind serialization and de-serialization is a recipe for bugs and misery the next time you add a feature.
Storing confidential data in the hash assures my users that I (the developer) don’t have access to this data, since anything after the hash never gets sent to the server by the browser.
It wouldn’t stop me from sending that information with a post request afterwards but the code is open source and it could be noticed in developer tools.
https://developer.mozilla.org/en-US/docs/Web/API/WindowBase6...
It is really unfortunate, because there are tons of use cases and zero reason to interfere with these requests.
The justification is also downright ridiculous. The argument is that "GET, DELETE, ... have no defined semantics for bodies". Meanwhile the 'defined semantics' for POST bodies is... whatever the application decides.
Reduces share urls by about 75% for these very repetitious JSON strings.