Back to the catalog

Compression on the web: Huffman, LZ77, Brotli, and the base64 tax

34 questions

Compression is the cheapest speed win on the web, and it's often applied to the wrong bytes. Learn what makes data compressible, how Huffman coding and LZ77 work, why Brotli beats gzip on text, and why inlining a file as base64 makes it a third bigger.

Questions

  1. Not answered. What does a compression algorithm exploit to shrink data?
  2. Not answered. Why does gzipping a file that's already .gz usually make it slightly bigger?
  3. Not answered. The pigeonhole principle and lossless compression
  4. Not answered. You need to gzip and encrypt a payload before sending it. Which comes first?
  5. Not answered. What should decide whether you export an image as lossless or lossy?
  6. Not answered. With these symbol frequencies (out of 100), which symbol gets the shortest Huffman codeword?
  7. Not answered. What's the shortest total length, in bits, of this 100-symbol message under an optimal Huffman code?
  8. Not answered. Why must Huffman codewords be prefix-free (no codeword is the start of another)?
  9. Not answered. What goes wrong when a code isn't prefix-free?
  10. Not answered. A symbol appears 99% of the time. Why can't Huffman coding spend less than 1 bit on it, and what can?
  11. Not answered. Static versus dynamic Huffman tables
  12. Not answered. LZ77 replaces a repeated run of bytes with a back-reference. What do the numbers in a (distance, length) pair mean?
  13. Not answered. An LZ77-based compressor has a 32 KiB sliding window. What's the largest distance, in bytes, a back-reference can reach?
  14. Not answered. Encoding abcabcabcabc by hand: how many back-reference tokens do you need?
  15. Not answered. DEFLATE runs LZ77 first, then Huffman coding. What kind of redundancy does each stage catch?
  16. Not answered. gzip, zlib, and raw deflate all use the same DEFLATE algorithm. Select every correct statement about how they differ.
  17. Not answered. Choosing a gzip compression level: 6 versus 9
  18. Not answered. Brotli ships with a large built-in dictionary of common web text. Why does that help it beat gzip on small HTML, CSS, and JS files?
  19. Not answered. Why does Brotli's lead over gzip shrink on a large, unique payload, like a big proprietary binary file?
  20. Not answered. Brotli quality levels: when is the highest one worth it?
  21. Not answered. Where does zstd usually sit on the speed/ratio curve compared with gzip and Brotli/xz?
  22. Not answered. A company serves thousands of small, similar JSON API responses and trains a custom compression dictionary on its past traffic. What's the idea?
  23. Not answered. A browser sends Accept-Encoding: gzip, br and gets a response with Content-Encoding: br. What does each header do?
  24. Not answered. How does Transfer-Encoding differ from Content-Encoding?
  25. Not answered. A server returns different bodies for the same URL based on Accept-Encoding but leaves out Vary: Accept-Encoding. What can go wrong?
  26. Not answered. For which of these does adding gzip or Brotli on top waste CPU for close to 0% extra savings?
  27. Not answered. Why do most servers skip compressing very small responses, say under about 1 KB?
  28. Not answered. A response mixes a secret token with attacker-controlled input and is compressed before being sent over HTTPS. What does the compressed length leak?
  29. Not answered. What's the standard defense against BREACH and CRIME-style compression attacks?
  30. Not answered. A binary file is exactly 300,000 bytes. About how many bytes is its base64 text, ignoring padding?
  31. Not answered. When does inlining an image as a base64 data URI help performance, and when does it hurt?
  32. Not answered. A CSS file embeds a large image as a base64 data: URI in a background-image rule. What's the downside of putting it in CSS instead of HTML?
  33. Not answered. You can minify a JS file before gzipping it, or gzip the unminified original. How does minification's raw-size saving compare with its saving after gzip?
  34. Not answered. Why does gzipping 200 small JSON files concatenated into one beat gzipping each file separately?