AVIF, WebP, or JPEG: choose formats by asset

Abstract media systems diagram for AVIF, WebP, or JPEG: choose formats by asset

A format decision based on content, compatibility, and operational cost.

Start with the content

Photographs usually tolerate lossy compression; diagrams and interface screenshots expose ringing around sharp edges. WebP and AVIF can reduce transfer size, but visual quality, encoding time, and decode behavior matter. Keep a widely supported fallback when the audience includes older clients or embedded browsers.

Measure at equal visual quality

Compare outputs at the same displayed dimensions and similar perceived quality, not at the same numerical quality setting. Include transparency, animation, color profile, and metadata needs. Save a small representative corpus of photos, text-heavy screenshots, and graphics for repeatable tests.

Negotiate without multiplying chaos

A picture element or a well-defined CDN content negotiation strategy can serve modern formats and a fallback. Ensure the CDN cache key distinguishes format variants. Do not allow arbitrary format and quality combinations to create an unbounded derivative library.

A concrete acceptance test

Encode one photo, one UI screenshot, and one transparent graphic in each candidate format. Compare the downloaded bytes and visible edges at the exact size users will see. Run this test with a realistic asset and record the observed state, output URL, and failure reason.

Implementation check

  • Compare formats at matched visual quality.
  • Include text-heavy screenshots and transparent graphics in tests.
  • Cache each negotiated format under a distinct key.

Related guides

Primary reference: Official documentation.