Skip to main content

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 ImageMaxRewritesAtOnce and 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 Accept header reaching the module. As with convert_jpeg_to_webp, a CDN or proxy that rewrites Accept or ignores Vary: Accept can 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_avif

nginx

pagespeed EnableFilters recompress_avif;

IIS (pagespeed.config)

pagespeed EnableFilters recompress_avif

On IIS, use the same filter names in pagespeed.config without the trailing semicolon — see IIS configuration.

ParameterDefaultDescription
AvifRecompressionQuality60AVIF quality level; -1 uses ImageRecompressionQuality
AvifRecompressionQualityForSmallScreens50AVIF quality for small-screen clients; -1 uses AvifRecompressionQuality
AvifAnimatedRecompressionQuality50Quality for animated AVIF output
AvifQualityForSaveData45AVIF quality for clients sending Save-Data: on
AvifTimeoutMs5000Wall-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_avif re-encodes AVIF images you already serve.
Is recompress_avif enabled by default?
No. recompress_avif is not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name with EnableFilters.
How do I enable recompress_avif on Apache and nginx?
Add ModPagespeedEnableFilters recompress_avif on Apache or pagespeed EnableFilters recompress_avif; on nginx. On IIS, add pagespeed EnableFilters recompress_avif to pagespeed.config.

This page is drawn from the recompress_avif entry on Image filters. Every filter in one table: PageSpeed filters.

Search