Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  129] [ 3]  / answers: 1 / hits: 19415  / 13 Years ago, fri, july 22, 2011, 12:00:00

Are there any libraries/etc. that implement lightweight text compression in JavaScript?



My real goal is to slightly shorten some text and make it inconspicuous at a glance. (It needn't provide security -- the text will be displayed for the user.) Ideally the compression could be tweaked to output only the query characters



[-._~!$&'()*+,;=:@/?a-zA-Z0-9]


so it can be passed in a URL. (Actually, this is kind of important -- if other characters are used they'd have to be percent-encoded, which will probably make the text larger than the original.) Of course rare characters could be percent-encoded if needed.



Any ideas? Failing that, suggestions for making a simple one? The compression doesn't have to be great but shorter URLs would be nicer. The text to be compressed should be English sentences: mostly lower-case letters, spaces, and punctuation with the occasional upper-case letters, digits, and newlines.


More From » compression

 Answers
43

I've found lz-string which is a perfect fit for my needs. It compresses and decompresses text rapidly and can target raw bits, valid Unicode characters, or Base64. Perhaps it will be useful for someone else?


[#91057] Thursday, July 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brianaclaras

Total Points: 23
Total Questions: 106
Total Answers: 111

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;