Wiki: ZTML - Extreme inline text compression for HTML/JS
For agents: Markdown version · Wiki index · Explore
- Speaker: Eyal Gruss
- Event: Reversim Summit 2022
- Video: https://www.youtube.com/watch?v=7rz_MfAIJnY
- Transcript: /transcripts/2022/17-7rz_MfAIJnY.md
- Language: Hebrew and English · Type: ignite · Level: advanced
- Topics: Performance, Algorithms, Frontend, AI and LLMs
Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.
Summary
The speaker introduces ZTML, a technique for extreme inline text and code compression designed for embedding large amounts of text into single HTML or JavaScript files. By combining creative text normalization tricks, Huffman encoding, and clever byte-level encodings like CP1252 instead of standard Base64, the speaker achieves compression rates that rival tools like 7-Zip. This approach allows developers to bundle complex generative art and text directly on-chain within strict size limitations. Ultimately, the audience learns how unconventional constraints can drive creative data compression and code golf techniques.
Key points
- 0:11 The speaker introduces the challenge of compressing 1000 haikus into a single 25-kilobyte HTML file.
- 1:13 Text preprocessing tricks, such as normalizing whitespace and removing redundant characters, help prepare text for compression.
- 2:14 Transforming data into an image and saving it as a PNG leverages the browser’s built-in PNG decompression engine.
- 2:14 Using single-byte encodings like CP1252 instead of Base64 significantly reduces the overhead when embedding binary data in text.
- 3:32 The resulting ZTML approach requires only a few lines of self-extracting JavaScript and achieves better compression than 7-Zip at maximum settings.
Takeaways
- Use single-byte encodings like CP1252 instead of Base64 to reduce overhead when embedding binary data inside text formats.
- Leverage browser capabilities, such as built-in PNG decoding, to handle data decompression on the client side without extra libraries.
- Apply unconventional text normalization rules to dramatically improve the compressibility of textual data.
Questions this talk answers
- How can I reduce the overhead of embedding binary data inside HTML compared to Base64?
- What are some creative text preprocessing techniques to improve compression ratios?
- How can browser-native image formats be utilized for client-side data decompression?
Technologies
JavaScript, HTML, PNG, Ethereum, Tezos, 7-Zip
Tags
code golf, compression, encoding, generative art, html, javascript, web3