Modern image formats like WebP and AVIF have brought visually identical images at a fraction of the file size provided by JPEG and PNG. With content negotiation allowing these formats to ship to the end user without breaking the experience for those using older browsers, all site owners should be prioritizing this optimization.
It is not practical to manually create multiple formats for each and every image. This is a job for tooling, which is why we consider the generation of these modern formats to be an essential feature.
Ideally, if a JPEG is requested with an
Accept header that includes
image/avif, it will return either a WebP or AVIF image.
An example of checking for AVIF using curl would look like this
$ curl 'https://cdn.example.com/imnage.jpg' \ -H 'accept: text/html,image/avif' \ -L -so output_image
From there, we check to see what the format of the returned image is.
$ file output_image output_image: ISO Media, AVIF Image
However, not all services offer respect accept headers, despite offering the image formats. In this case, they are manually set to