just built a small webapp for previewing HTML-documents that generates URL:s containing the HTML (and all inline CSS and Javascript) in base64 encoded data. Problem is, the URL:s quickly get kinda long. What is the "de facto" standard way (preferably by Javascript) to compress the string first without data loss?
PS; I read about Huffman and Lempel-Ziv in school some time ago, and I remember really enjoying LZW :)
EDIT:
Solution found; seems like rawStr => utf8Str => lzwStr => base64Str is the way to go. I'm further working on implementing huffman compression between utf8 and lzw. Problem so far is that too many chars become very long when encoded to base64.
There is no "shorter version" of base64. But what you can do is retrieve only the first characters of the base64 result; with cut for instance. Using cut this way is also safe if the base64 result is shorter than 10 characters.
AFAIK It's impossible to shrink a base64 code. Short answer, cannot be done/makes no sense.
Although Base64 is a relatively efficient way of encoding binary data it will, on average still increase the file size for more than 25%. This not only increases your bandwidth bill, but also increases the download time.
Make a loop at the end of the string After cutting the string at the proper length, take the end of the string and tie a knot at the very end, then fold the string over and tie a loop, about the same size as the original loop (about 2cm in diameter).
Check out this answer. It mentions functions for LZW compression/decompression (via http://jsolait.net/, specifically http://jsolait.net/browser/trunk/jsolait/lib/codecs.js).
You will struggle to get very much compression at all on a URL, they're too short and don't contain enough redundant information to get much benefit from Huffman / LZW style algorithms.
If you have constraints on the space of possible URLS (e.g. all content tends to be in the same set of folders) you could hard code some parts of the URLS for expansion on the client - i.e. cheat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With