Rough name, isn’t it? JPEG XL. Like JPEG’s, but bigger! That’s, uhhh, not desireable in image format land.

Also, I always kinda cringe at using the full image.jpeg extension. I’m an image.jpg kinda guy. Good news here though, it looks like the official extension is actually image.jxl. That should be useful in differentiating for non-supporting browsers, which we’ll get to.

JPEG XL a real fancy new format evolution for JPEG and support is getting there across all browsers. So we should understand what it’s good for and how we can use it. Therein lies the problem. It’s been getting muddier and muddier on what image formats we should actually attempt to use. I wish it was this simple:

if (fancyNewBetterFormatSupported) {
  <img src="/images/img.avif-or-whatever" alt="..." />
} else {
  <img src="/images/img.jpeg" alt="..." />
}Code language: HTML, XML (xml)

I’m tempted to say: but we don’t have ‘if’ statements in HTML! — but we kinda do.

Let’s say we had the same image as a (uh, traditional?) JPG, then we created theroetically-more-efficient versions of it in WebP, AVIF, and now JPEG XL too. We could list them out like this:

<picture>
  <source srcset="photo.jxl"  type="image/jxl">
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" alt="Describe the image" width="1200" height="800" loading="lazy">
</picture>Code language: HTML, XML (xml)

That’s going to play like:

  1. If the browser supports JPEG XL, use that.
  2. If the browser supports AVIF, use that.
  3. If the browser supports WebP, use that.
  4. Otherwise fall back to JPEG

But hold up.

Nobody should implement this blindly across all images. It’s never been this straightforward, even before JPEG XL. There isn’t a “ranking” where certain image formats are just straight up better than others in all situations. And we haven’t even included SVG and weird hybrid stuff you can do.

Google notes in their announcement:

In general, we recommend trying both AVIF and JPEG XL to get the best results. We expect that JPEG XL is most helpful for high-fidelity or lossless compression, especially of photographic images or in cases in which fine-grained progressive decoding is preferred.

So like sometimes it’s good (as in, better than both AVIF and WebP), but it’s hard to know exactly when, but probably when it’s a super detailed photograph and you’re going for retaining that detail, not compressing it.

There are also other behaviors to consider, as JPEG XL has that fancy “progressive decoding” thing where a low-res version of the image loads first, and it gets more detailed as it loads. That could be considered a perceived performance benefit, which is a good thing. Except it doesn’t work in Safari (yet?) and it turns out AVIF has this ability too and maybe does it even better.

There is a great (and quick) Jake Archibald video on the basics here you should watch:

I felt like that video was relatively damning against JPEG XL, showing that it rarely is any better than AVIF in quality and slower to encode to boot, meaning it would be rarely useful unless you truly need lossless compression. But Jake also notes it’s a rapidly evolving area.

Jake wrote a full-blown article digging in a lot deeper, and the results are even more damning. From what I can see here, the only thing JPEG XL is any better at (compared to AVIF) is lossless encoding and the occasional high-res photo, and it is fairly significantly worse at a lot of other stuff.

Gianni Rosato also has a deep inside look at JPEG XL (from a place of some involvement) and concludes it just ain’t that useful on the web. Maybe off-web it has more of a place. This is a good note:

Also worth mentioning both JPEG XL and AVIF are royalty-free.

Me, I don’t want to have to think about it. I care, but on an image-to-image basis in day-to-day website work, I can’t be stopping to think what format is going to serve the situation best. I want technology to do what technology does and make the right choice based on data.

I like doing this sort of thing:

<img 
  src="https://cdn.com/image.jpg?format=auto"
  alt=""
  width=""
  height=""
  loading="lazy"
/>Code language: HTML, XML (xml)

Annnnd done.

The ?format=auto being the extra pertinant bit here. Who decides that? The fancy image CDN does. It takes the original, compresses it in all the formats, figures out what is best, and serves that, also factoring in what the browser capabilities are of the browser requesting it.

That’s what I want out of image tech, and we largely already have it. Services like Cloudinary do it, and support JPEG XL already.

Here at CodePen, we offer image hosting with auto-formatting, and it’s powered by Cloudflare. Cloudflare has AVIF support, but I don’t think has said anything about JPEG XL yet, and based on what we have learned here, I sorta doubt there are gonna rush it out.