filter · Image filters
Recompress AVIF (recompress_avif)
- Category:
- Image
- CoreFilters:
- No
- OptimizeForBandwidth:
- No
- Risk:
- Test first
recompress_avif re-encodes AVIF images you already serve.
How it works
Four filters transcode images to AVIF.
All four are opt-in. They sit outside rewrite_images and outside the CoreFilters set, so enabling rewrite_images alone produces no AVIF output — you have to name the AVIF filters you want.
AVIF is served only when the request advertises Accept: image/avif. There is no User-Agent sniffing. A client that does not advertise AVIF falls through the existing format order unchanged. The cache key folds in the client’s AVIF capability, so variants are stored and served per capability exactly as WebP variants are.
The AV1 encoder is statically linked into the module. There is no separate package or codec library to install.
Caveat: RewriteLevel AllFilters enables all four
“Opt-in” holds for filters you name explicitly. The four AVIF filters are not in the dangerous-filter set, so RewriteLevel AllFilters switches all of them on. If you run AllFilters, you are running the AVIF filters whether or not you listed them.
When to use it
- Not in CoreFilters: it runs only when you enable it by name.
- Risk rating on these docs: Test first.
Risks
-
An AVIF candidate costs a full extra decode and encode per image. The module encodes an AVIF candidate and keeps it only if it beats the WebP or optimized-original candidate. Each candidate is produced from its own decode; the decode is not shared between formats. AV1 encoding is also slower than WebP encoding at comparable quality, so enabling AVIF measurably raises the CPU cost of the first rewrite of every image. Watch
ImageMaxRewritesAtOnceand the rewrite deadline on busy origins. -
Pick-smaller means some of that work is discarded. When the AVIF candidate is not smaller, it is dropped and the existing variant is served. The CPU is spent either way.
-
Images with C2PA content credentials are not converted. A source carrying a C2PA manifest is left alone by all four filters, so its provenance chain survives the pipeline.
-
Delivery depends on the
Acceptheader reaching the module. As withconvert_jpeg_to_webp, a CDN or proxy that rewritesAcceptor ignoresVary: Acceptcan cross-serve formats. Test with your CDN configuration before rolling out.
Configuration
Enable it in the module configuration, at server, virtual-host or location scope:
Apache
ModPagespeedEnableFilters recompress_avifnginx
pagespeed EnableFilters recompress_avif;IIS (pagespeed.config)
pagespeed EnableFilters recompress_avifOn IIS, use the same filter names in pagespeed.config without the trailing semicolon — see IIS configuration.
| Parameter | Default | Description |
|---|---|---|
AvifRecompressionQuality | 60 | AVIF quality level; -1 uses ImageRecompressionQuality |
AvifRecompressionQualityForSmallScreens | 50 | AVIF quality for small-screen clients; -1 uses AvifRecompressionQuality |
AvifAnimatedRecompressionQuality | 50 | Quality for animated AVIF output |
AvifQualityForSaveData | 45 | AVIF quality for clients sending Save-Data: on |
AvifTimeoutMs | 5000 | Wall-clock budget for one AVIF encode; the encode is abandoned when it is exceeded |
These mirror the Webp* quality parameters: a value of -1 falls back to the more general setting, so you can set ImageRecompressionQuality alone and let AVIF follow it.
AvifTimeoutMs exists because AV1 still-image encoding is materially slower than WebP. The budget stops one expensive image from occupying a rewrite slot indefinitely; when it is hit the AVIF candidate is abandoned and the existing WebP or optimized-original output is served, so a timeout costs CPU but never a broken image. Raise it if large photographic sources are being skipped, lower it if AVIF encodes are crowding out other rewrites.
Scoping, ForbidFilters and the thresholds filters read:
Choosing filters
.
Frequently asked questions
- What does the recompress_avif filter do?
recompress_avifre-encodes AVIF images you already serve.- Is recompress_avif enabled by default?
- No.
recompress_avifis not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name withEnableFilters. - How do I enable recompress_avif on Apache and nginx?
- Add
ModPagespeedEnableFilters recompress_avifon Apache orpagespeed EnableFilters recompress_avif;on nginx. On IIS, addpagespeed EnableFilters recompress_avifto pagespeed.config.
Related filters
- convert_jpeg_to_avif — Convert JPEG to AVIF
- convert_to_avif_animated — Animated AVIF
- convert_to_avif_lossless — Lossless AVIF
- convert_gif_to_png — Convert GIF to PNG
- convert_jpeg_to_progressive — Progressive JPEG
- convert_jpeg_to_webp — Convert JPEG to WebP
- convert_png_to_jpeg — Convert PNG to JPEG
- convert_to_webp_animated — Animated WebP
This page is drawn from the recompress_avif entry on Image filters. Every filter in one table: PageSpeed filters.