auto
Enables optimizations based on content negotiation.
The only negotiated optimizations currently available are for AVIF and WebP, both image compression formats with limited browser support.
This functionality is also possible using format=auto
which adds additional support for JPEGXL output.
Syntax
auto={value}
Allowed values
Value | Description |
---|---|
avif | If the browser's Accept header indicates compatibility, deliver an AVIF image. |
webp | If the browser's Accept header indicates compatibility, deliver a WebP image. |
Notes
- Although the AVIF and WebP formats produce images at a higher compression ratio with a lower loss of quality compared to JPEG, they are not supported in all browsers.
- When using Firefox version 66 to 71, automatic content negotiation will not occur when navigating to the image. To view WebP or AVIF images generated via
auto=avif
orauto=webp
you must insert your image onto a web page. - AVIF is a premium feature of Fastly's Image Optimizer and choosing it as an encoding format will increase your bill. Charges will appear on your service order.
format=auto
will take precedence if combined withauto
.
Examples
Click the links to view the transformed image using a demo Fastly IO service.
Example usage | Description |
---|---|
?auto=avif | Deliver lossy AVIF from the lossless input image where client support is available, otherwise deliver a PNG |
?auto=webp | Deliver lossless (because input image is lossless) WebP where client support is available, otherwise deliver a PNG |
?format=pjpg&auto=webp | Deliver lossy (because format=pjpg is lossy) WebP where client support is available, otherwise deliver a progressive JPEG |
?format=png&auto=webp | Deliver lossless (because format=png is lossless) WebP where client support is available, otherwise deliver a PNG |
Multiple format selection
Browsers that do not support AVIF may support WebP. You may wish to select from more than one possible negotiated format, based on browser support and a prioritized list of formats in a preferred order. Often this is AVIF, then WebP, then JPEG. This can be achieved by adding some custom VCL to your service:
sub vcl_recv { ... }
Fastly VCL
if (querystring.get(req.url, "auto") == "avif,webp") { if (req.http.Accept ~ "\bimage/avif\b") { set req.url = querystring.set(req.url, "auto", "avif"); } elsif (req.http.Accept ~ "\bimage/webp\b") { set req.url = querystring.set(req.url, "auto", "webp"); }}