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.
What is Code Compression? To compress, minimize or minify code simply refers to removing unnecessary characters from the source code like white spaces, new line characters and a host of redundant data without actually affecting how the code or resource as a whole is processed by the browser.
Definition. Text Compression involves changing the representation of a file so that the (binary) compressed output takes less space to store, or less time to transmit, but still the original file can be reconstructed exactly from its compressed representation.
gzip-js is a pure JavaScript implementation of the GZIP file format. It uses the DEFLATE algorithm for compressing data. Please note that since this is a pure JavaScript implementation, it should NOT be used on the server for production code. It also does not comply 100% with the standard, yet.
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?
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