简体   繁体   中英

Javascript : Working with a large JSON object / string in URL

I have quite a specific demand, and I wonder if this is even possible.

I am writing a client-side application in Javascript / jQuery, but I can't store anything. I'm using an external library which needs a Javascript object as an initial parameter, and this object can be quite large (at least more than 6000 characters, it could be way more than that). I would like to be able to "share" this Object through the URL, so any client could rebuild the application with a specific configuration object. The URL would be ugly but I could live with that I guess, the main problem is the maximum characters an URL can contain in IE (11+) : ~2000. Apparently other main browsers can take a very long hash without any problem.

At first, I searched around string compression libraries (lzw, pako...), and while those libraries often do a great job for short strings, those can't help me with the huge JSON I need to share.

I'm open to any suggestions. If there is any other way than passing it through the URL, I would be interested, but I'm afraid without the ability to store anything server-side, there is not.

Have you tried the:

window.location.hash

Worked well on updated Safari, Firefox & Chrome: URL lenth of 60000+ was tolerated...

yoururl.com/#yourverylongstring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM