Compressing AVIF with Gzip or Brotli on Web Servers

Web servers decide whether to compress an AVIF file using Gzip or Brotli by evaluating client capabilities, matching server-side MIME type configurations, and applying compression threshold rules. However, because AVIF is an intrinsically compressed image format, standard web server configurations deliberately skip HTTP compression for AVIF files to conserve CPU cycles and prevent file size inflation.

The HTTP Handshake: Checking the Accept-Encoding Header

The evaluation process begins when a client sends an HTTP request containing the Accept-Encoding header. This header tells the server which compression algorithms the browser supports:

Accept-Encoding: gzip, deflate, br, zstd

If the client does not explicitly list gzip or br (Brotli), the server cannot apply that compression algorithm to any file, including AVIF.

MIME Type Filtering

Servers do not inspect raw image data to decide whether compression is worthwhile; instead, they check the resource's MIME type against a configured inclusion list.

For an AVIF image, the server assigns the image/avif MIME type. By default, production servers do not include image/avif in their compression whitelists. If image/avif is absent from these directives, the server transfers the file as-is with no transfer encoding, regardless of what the browser requested.

Algorithm Selection and Precedence

If an administrator explicitly adds image/avif to the compression whitelist, the server evaluates both available methods:

  1. Client Support: The server checks whether br, gzip, or both are listed in the Accept-Encoding header.
  2. Algorithm Priority: When both the client and server support both algorithms, modern web servers prioritize Brotli over Gzip due to its higher compression density.
  3. Threshold Rules: The server checks minimum file size constraints (such as Nginx's gzip_min_length). Files below this threshold are transmitted uncompressed.

Why Web Servers Typically Bypass AVIF Compression

AVIF uses the AV1 video codec's intra-frame compression, meaning the image data is already packed near maximum theoretical entropy.

Applying Gzip or Brotli on top of an already compressed binary format provides virtually zero byte reduction. In many instances, the overhead of compression headers and dictionary tables can cause negative compression, resulting in a larger payload than the original image while unnecessarily consuming server and client CPU resources.