3 ms·
On <!DOCTYPE html> versus <!doctype html>: it’s actually not so simple. If you’re using gzip, you might manage to save as much as a few bytes (though typically
by chrismorgan 3y ago
On <!DOCTYPE html> versus <!doctype html>: it’s actually not so simple. If you’re using gzip, you might manage to save as much as a few bytes (though typically only 1–2), but if you’re using Brotli, it’ll actually compress something like 2–4 bytes worse, because Brotli includes a static dictionary based on a popularity contest of largely-not-optimised content.
This is a thing I dislike about Brotli: it encourages you to follow the herd, rather than doing what would otherwise be more optimal. (Sure, the encouragement is just a byte here, a byte there, but it’s the principle of the thing.)
Here are sizes based on running `‹brotli or gzip› --stdout <<<'‹doctype›‹charset›' | wc -c`:
┌─────────────────┬────────────────────────┬──────────────────────┐
│ BROTLI │ <meta charset="utf-8"> │ <meta charset=utf-8> │
├─────────────────┼────────────────────────┼──────────────────────┤
│ <!DOCTYPE html> │ 19 │ 27 │
│ <!doctype html> │ 23 │ 29 │
└─────────────────┴────────────────────────┴──────────────────────┘
┌─────────────────┬────────────────────────┬──────────────────────┐
│ GZIP │ <meta charset="utf-8"> │ <meta charset=utf-8> │
├─────────────────┼────────────────────────┼──────────────────────┤
│ <!DOCTYPE html> │ 58 │ 56 │
│ <!doctype html> │ 58 │ 56 │
└─────────────────┴────────────────────────┴──────────────────────┘
In practice, when you add more content, predominantly lowercase, doctype tends to save a byte or two compared to DOCTYPE. So gzip gravitates to the bottom left corner—that removing unnecessary characters and matching case where case-insensitive is good. But Brotli was made by popularity contest, and so the inferior representation actually ends up compressing better than the superior, because most people did things the inferior way!
- lifthrasiir 3y agoBut the static dictionary is not used as is, but transformed with a lot of options. For example both `<!DOCTYPE html>` and `<!doctype html>` appear in the dictionary, and the transform 43 (FermentAll) will turn them into `<!DOCTYPE HTML>`. (No transform would generate `<!doctype HTML>` though.) Therefore Brotli is not only following the herd, so to say. And the static dictionary only improves a very short input---any long-term pattern will be captured regardless of the static dictionary.
- chrismorgan 3y agoI believe that when I investigated this a few years ago I tried it on a few things and found it consistent. Right now, I take my HN front page and add <!DOCTYPE html> and <!doctype html>. Uppercase becomes 5678 bytes; lowercase 5675 bytes, three bytes smaller.
- lifthrasiir 3y agoWhile Brotli tries to use all those transforms, I guess it is still not exhaustive enough to fully make use of them, given that Brotli (and many others) is asymmetric in design and compressors can be heavily tweaked without affecting decompression too much.