skip to content

Which image format should a fashion catalogue app's photos arrive in, and how is it negotiated when two-year-old builds on older OS releases are still installed?

level: seniorimportance: should knowfreq 38%

answer

  1. the device states what it decodes
  2. ask the decoder, not the build number
  3. the default is the universal format
  4. the cache must see what was negotiated
  5. a failed decode retries as JPEG

basics

~20 s

The app tells the server which formats this device decodes; the server picks the best of those and falls back to JPEG. Caches must see the choice, via Vary or the URL, so one phone's AVIF never reaches another.

solid answer

~40 s

Not every OS release decodes every format: one platform's own table lists HEIF decode from one release and AVIF only from a much later one. So the app builds its list at runtime from what this device's decoder supports, and sends it either as image types in `Accept` or as a format the app picks into the URL. If it uses `Accept`, the response must carry `Vary: Accept`, or a shared cache hands an AVIF chosen for a new phone to an old one, which shows a blank tile. The server's default for a missing or wildcard list is the universal format, JPEG, never the newest. A two-year-old build that only knows WebP and JPEG keeps getting those. And the app treats a decode failure as a cue to re-request JPEG and report it.

code

http · 8 lines
http
GET /p/8812/w640 HTTP/1.1
Host: images.example.com
Accept: image/avif, image/webp, image/jpeg

HTTP/1.1 200 OK
Content-Type: image/avif
Vary: Accept
Cache-Control: public, max-age=31536000

go deeper

for a junior

Remember that decode support depends on the OS release, so the app must say which formats it can decode and JPEG is always the fallback.

for a middle

Explain the two carriers, Accept with Vary and a format in the URL, and why a cache that does not see the negotiation hands one phone's format to another.

for a senior

Show the old-build plan: runtime capability lists, a JPEG default for missing or wildcard lists, decode-failure fallback and reporting by OS release and app version.

for a principal

Decide which formats the estate produces and when one may be retired, weighing storage and encode cost against bytes saved and the long tail of old devices.

## The problem in one sentence Newer image formats such as **AVIF** and **WebP** usually give smaller files than **JPEG** at similar visual quality, but **not every device can decode them**, and a catalogue app with builds up to two years old on many OS releases will meet phones that cannot. A phone sent a format it cannot decode shows nothing. Two facts frame the design: - Decode support is a property of the **OS release**, not only of the app. One platform's published format table lists HEIF (the `.heic` and `.heif` files) as decodable from one OS release and AVIF only from a much later one, so two phones running the same app build can differ. - **HEIC** is a common capture format on some phones, which does not make it a safe delivery format; it is delivered only to devices that say they decode it. ## Step 1: the device states what it can decode The app asks the platform's decoder, at runtime, which formats it supports, and builds an ordered list: for example AVIF, WebP, JPEG on a new OS, and WebP, JPEG on an older one. The list comes from capability, not from the app's version number, because the same build runs on many OS releases. JPEG is always last and always present. ## Step 2: carry the list to the server There are two common carriers, and both work for an installed app: | Carrier | How it looks | Cache behaviour | Weakness | |---|---|---|---| | `Accept` request header | `Accept: image/avif, image/webp, image/jpeg` | The response must say `Vary: Accept`; the CDN should normalise the header to a few known values | An `Accept` the server does not recognise, or a wildcard, must not be read as "anything" | | Format in the URL | `/p/8812/w640.webp`, chosen by the app from the server's list | One URL is one representation; no `Vary` needed | The app must know the server's format list, so it comes from the API response or configuration | HTTP's own rules make the cache requirement explicit. A response whose content was selected using a request header should list that header in `Vary`, and a cache must not reuse the response for a later request whose listed header values differ. A server that chooses AVIF from `Accept` but omits `Vary: Accept` lets a shared cache hand that AVIF to the next phone, whatever it sent. The symptom is nasty to debug: **some** users on **some** older phones see blank tiles, intermittently, depending on who warmed the cache first. How `Vary` and `Accept` work as protocol is the HTTP layer's business; the design point here is that the negotiation must be visible to every cache between the server and the app. ## Step 3: the server's fallback rules 1. Pick the first format in the client's list that the server has produced for this image. 2. If the list is missing, unrecognised, or a bare wildcard, serve **JPEG**. A default HTTP client in an old build may send a generic `Accept`; it is not a promise to decode AVIF. 3. Never retire JPEG while any installed build can reach the server. 4. When a new format is introduced, only clients that list it receive it; nothing changes for old builds. HTTP also allows a server that finds nothing acceptable either to answer `406` or to ignore the header and send something anyway, and it notes that the client may then be unable to use what it gets. So the client needs its own safety net. ## Step 4: the client's safety net - If decoding a response fails, re-request the same width as JPEG once, and display that. - Report the failure with the OS release, app version, format and image URL, so a server change that broke one cohort shows up as a spike rather than as one-star reviews. - Do not cache the undecodable bytes on disk under the photo's key. ## Old builds A build installed two years ago has whatever list-building logic it shipped with. If it hardcoded "WebP, JPEG", it keeps sending that, and the server keeps honouring it. If it sent a format in the URL from a list it compiled in, the server must keep serving those URLs. The rule is the same expand-then-contract discipline as any API: add formats for clients that ask, and never change what an existing request means. ## Quality versus bytes, briefly The format is one lever on bytes; the encoder's quality setting is another. Higher-density screens can usually take a lower quality setting without a visible difference, because each pixel is smaller, so bytes grow less than the pixel count. That is a server-side encoding policy; the app's part is to send the density and the format list honestly and let the server apply it.

  • Some users on older phones report blank product tiles, but only sometimes. What do you suspect first?
    A cache serving a negotiated format to a client that cannot decode it: the server picked AVIF from `Accept` but the response lacks `Vary: Accept`, or the CDN strips or ignores it, so whoever warmed the cache decides what everyone gets. Check the response headers at the edge and the decode-failure reports grouped by OS release.
  • Why build the format list from the decoder at runtime instead of from the app version?
    The same app build runs on many OS releases, and decode support follows the OS. A version check would claim AVIF on an old OS that cannot decode it, or deny it on a new one that can.
  • When would you choose the format-in-URL carrier over Accept?
    When the CDN in front handles `Vary` poorly or caches many header variants badly. A format in the URL makes each URL one representation, which every cache understands, at the cost of the app needing the server's format list from the API or configuration.

  • Serve AVIF to everyone; every phone that can run the app decodes it.
  • The app's version number tells you which formats the device can decode.
  • A response chosen from Accept needs no Vary because the URL is the same.
  • A wildcard Accept from an old build means it can decode any format.
  • If a phone cannot decode the format, the platform converts it automatically.