The problem
localStorage only holds a few megabytes, and URLs have length limits. Text compresses well, but most compression formats produce binary data, which neither of them can store.
What it does
- LZ-based compression, written for JavaScript.
- Outputs the kind of string you need: UTF-16 for localStorage, URI-safe for URLs, Base64, or a Uint8Array.
- Comes with a command line tool.
- Ported to many other languages, Java included, so a server can read what the browser compressed.
Get started
import LZString from "lz-string";
const packed = LZString.compressToUTF16(text);
const unpacked = LZString.decompressFromUTF16(packed);
Or from the command line, once installed globally:
lz-string input.txt > output.txt