How Cloudflare Polish Automates AVIF Optimization

Cloudflare Polish streamlines web performance by automatically compressing and converting images into modern formats like AVIF at the network edge. This article explains the underlying mechanism of Polish, detailing how it detects browser support via HTTP headers, processes conversions dynamically without altering origin assets, evaluates compression efficiency, and caches the optimized results to accelerate content delivery.

Client Capability Detection

The automation process begins at the edge when a user requests an image asset. Cloudflare inspects the incoming HTTP Accept request header sent by the client's web browser. If the browser supports AVIF, the header explicitly includes image/avif. Polish reads this signal to determine whether it is eligible to serve an AVIF version instead of the original JPEG, PNG, or WebP file.

Origin Retrieval and Edge Evaluation

When a request is received, Cloudflare checks its edge cache for an already optimized version matching the client’s capabilities. If a cache miss occurs, Cloudflare fetches the original asset from the origin server. Polish then intercepts the response before delivering it to the user. This architecture eliminates the need for developers to pre-generate, store, or manage multiple format variations on the host server.

On-the-Fly AVIF Encoding

Once the original image is retrieved, Polish applies its compression algorithms based on the user's dashboard configuration—Lossless or Lossy:

During this stage, the edge worker or internal daemon encodes the image into the AVIF format. AVIF leverages the AV1 video codec's intra-frame compression, yielding files that are typically 50% smaller than JPEGs and significantly smaller than WebP equivalents.

Safeguards and Quality Checks

Cloudflare does not blindly serve the converted AVIF. Polish compares the byte size of the newly generated AVIF file against the original image. If the AVIF output turns out to be larger than the original asset—a rare scenario that can happen with very small or pre-optimized images—Polish discards the AVIF version and serves the original format to ensure optimal delivery efficiency.

Caching and the Vary Header

After a successful conversion, Cloudflare stores the optimized AVIF in the edge cache to serve subsequent requests instantly. To prevent serving AVIF files to browsers that do not support the format, Cloudflare automatically manages the Vary: Accept HTTP response header. This ensures downstream caches and CDNs maintain distinct versions of the image, seamlessly serving AVIF to modern browsers while providing legacy formats to older clients without changing image URLs.