Javascript string compression for URL hash parameter

I am looking to store a large amount of data in a hash URL parameter without exceeding the URL character restrictions.

Are there any conventional ways to compress the length of a string that can then be decoded on another page load?

I saw the LZW encoding used for such solutions, however, are special characters applicable for this use?

+6
source share
2 answers

LZW coding technically works; you just need to convert the binary encoded in LZW to safe for the base64 database so that the output does not contain special characters. Here's a base64 MDN article in JavaScript ; base64's URL safe version simply replaces + with - and / with _ . Of course, you are unlikely to reduce the size of your row by doing this, if only the data you want to save is extremely compressible.

+1
source

You can see smaz or shoco , which are designed to compress short strings. Most compression methods do not actually roll up to the desired URL length limit, so for this you need a specialized compressor if you expect to get any gain. You can then encode the binary result using a Base 64 type scheme or more efficient encoding that uses all secure URI characters.

+1
source

Source: https://habr.com/ru/post/982213/


All Articles