A bit of history#
GIF is the oldest widespread compressed image format. Today, it is mostly famous for allowing animations in an image file, but I am not so interested in that use.
Actually, it turns out this was the only image format ever supported by NCSA Mosaic. Your website must have a GIF fallback for all critical images if it ever wants to truly support old browsers. I’m not talking old as in old Chromium. I mean actual Mosaic, Netscape, IE, Netsurf, Dillo, Konqueror - like those you can try on oldweb.today. (You are probably not interested in supporting them, but this is a fun exercise.)
I really wanted the 1-Click Linux website to look acceptable even in the oldest browsers, so I decided that I would use <picture> with fallback to GIF. I believe each modern web feature, if used in production, should be reasonably widely compatible on itself already, and then only have one fallback, which should be the one with absolute 1000% compatibility.
The problem is, GIF compression is not impressive. Let’s face it, in 2026 you should most likely only use SVG and WebP (lossy for photos, lossless for small-pallette drawings/logos). Not PNG, not JPEG, and God forbid AI, DWG or any other proprietary format (looking at you, DICOM). Well, okay, at least on the web (as the name says, WebP).
A partial solution is to use a small image. The truly old devices have truly small screen sizes, like 240x320 Nokia phones. So an icon or logo fallback can safely be 128x128, as 256x256 might not even fit on the screen.
Can we do better? Yes. There is an entire field dedicated to image optimisation, and it starts with stripping metadata. Then we can remove unused colors from the palette, then remove rarely used colors from the palette, and so on.
But none of the steps above mention actual compression itself!
I heard about zopflipng. PNG uses DEFLATE, the compression format known from ZIP and GZIP. This is a variant of LZ77 with Huffman coding. In this format, and quite commonly in other compression formats, there are many different ways to represent the exact same uncompressed data.
DEFLATE is also the name of an algorithm that generates a reasonably compressed input, and it can be tuned to spend more time compressing in hopes to achieve better compression (for the same data, remember?). But there are many syntactically valid DEFLATE streams that are never produced by DEFLATE the algorithm, which is kind of funny, because you can make a ZIP that contains itself, but anyway, some of them are even better than the largest ‘compression level’.
... continue reading