Image CDN

On this page 7

An image CDN is a content delivery network that transforms images on the fly (resizing, cropping, compressing and converting formats) based on URL parameters or request headers, and then caches each generated variant at the edge. In content delivery, it combines the distribution role of a general CDN with a real-time image processing pipeline, so one master file can serve thousands of devices in the size and format each one needs.

Images typically account for the largest share of bytes on content-heavy web pages, and they often determine the Largest Contentful Paint metric. An image CDN attacks that weight directly: instead of developers exporting dozens of renditions by hand, the network produces optimized derivatives on demand and keeps them close to users.

How an image CDN processes a request

An image CDN works as a transform-then-cache pipeline. A request such as /photo.jpg?w=800&q=75&fm=auto reaches the nearest point of presence. If that exact variant is already in the edge cache, it is returned immediately. On a miss, the CDN fetches the master image from the origin server or its own storage, applies the requested operations, stores the result and returns it.

The steps below describe the typical path of a first request for a new variant.

  1. Parse the transformation from URL parameters, a path segment or a named preset.
  2. Negotiate the format by reading the Accept header, for example to choose AVIF or WebP.
  3. Retrieve the master file from the origin, often through an origin shield to protect it.
  4. Decode, transform and re-encode the image with the requested width, quality and crop.
  5. Cache the derivative under a key that includes every parameter that changed the output.

Correct cache key design is critical. When the output format depends on the Accept header, the response must carry Vary: Accept or the CDN must normalize format into the key; otherwise a browser without AVIF support could receive an AVIF file cached for another client.

Transformations an image CDN performs

Image CDNs expose a set of declarative operations that replace manual export work. The most valuable ones reduce bytes without visible quality loss, while others adapt composition to different layouts.

OperationTypical parameterMain benefit
ResizeWidth or height in pixelsAvoids sending oversized images
Format conversionAutomatic or explicit formatSmaller files in AVIF or WebP
Quality adjustmentQuality 1-100 or perceptual targetBalances size and artifacts
Smart cropGravity, focal point or face detectionKeeps the subject in frame
Device pixel ratioDPR 1, 2 or 3Sharp output on dense screens
Metadata strippingRemove EXIF and color profilesSaves bytes and protects privacy
Common transformations and their effect

Format choice has the largest single effect. At comparable perceived quality, WebP is commonly 25-35% smaller than JPEG and AVIF often saves more again, although exact gains vary with content, encoder settings and the quality metric used. AVIF encoding is also considerably slower, which matters on cache misses.

An image CDN differs from a general CDN because it creates content rather than only copying it. A conventional CDN caches whatever bytes the origin returns, so every rendition must already exist. Build-time optimization, by contrast, pre-generates fixed sizes during deployment but cannot react to new devices or formats.

ApproachWhere variants are createdFlexibilityMain drawback
Image CDNAt the edge, on first requestAny size or format on demandPer-transformation cost and vendor lock-in
General CDNAt the origin, before uploadOnly pre-made filesManual or scripted rendition work
Build-time pipelineDuring site buildFixed breakpointsLong builds and stale formats
Self-hosted resizerOn an origin image serverHigh, under own controlMust be scaled and cached separately
Ways to deliver optimized images

Many teams combine approaches: a self-hosted or open-source resizer behind a general CDN can behave like a basic image CDN, provided cache keys, format negotiation and origin protection are handled carefully.

Configuring an image CDN for performance

Good results come from limiting variant explosion while still matching real layouts. Every distinct combination of width, quality and format becomes a separate cache object, so unbounded parameters lower the cache hit ratio and raise processing costs.

SituationRecommended choiceReason
Responsive layoutsFixed width steps, for example every 200 pxKeeps the number of variants bounded
Mixed browser audienceAutomatic format with Vary: AcceptServes AVIF or WebP safely
Hero and LCP imagesPreload and higher priority hintsImproves Largest Contentful Paint
User-generated uploadsSigned URLs and size limitsBlocks abuse of the transform engine
Rarely viewed archivesLong TTL with origin shieldReduces repeated origin fetches
Configuration decisions

On the page side, the image CDN works best with responsive markup: srcset and sizes let the browser pick the right width, and explicit width and height attributes prevent layout shift. Long Cache-Control lifetimes are safe when URLs are versioned, because a changed image simply receives a new URL instead of requiring a cache purge.

Limitations and risks of an image CDN

The main limitations of an image CDN are cost, latency on misses and dependency on one provider. Pricing is often based on transformations, delivered bytes or the number of unique source images, so a careless parameter scheme can multiply the bill. The first request for a new variant can take hundreds of milliseconds while the image is processed.

  • Denial-of-wallet attacks: arbitrary width parameters let attackers force endless unique transformations; signed URLs or allow-lists prevent this.
  • Quality drift: aggressive automatic compression can introduce banding or blurred text in screenshots and diagrams.
  • Color handling: stripping ICC profiles can shift colors in wide-gamut product photography.
  • Lock-in: proprietary URL syntax spreads through templates and content, making a later migration expensive.

An image CDN also cannot fix poor source material or unnecessary images. It optimizes delivery of what the page requests, so oversized layout slots and decorative images loaded above the fold remain design problems.

The idea in brief

A website usually stores one large, high-quality version of each photo. Phones, laptops and large monitors all need different sizes, and some browsers understand newer, lighter file types than others.

An image CDN is like a photo lab with branches all over the world. When a visitor asks for a picture, the nearest branch prints exactly the right size in the most efficient format, hands it over and keeps a copy for the next visitor who needs the same one. The website keeps one original, and every device still gets a fast, well-fitted image.

A practical scenario

An online furniture retailer has about 40,000 product photos, each uploaded as a 4,000-pixel JPEG of roughly 3 MB. Its mobile category pages were loading full-size files scaled down by the browser, and the Largest Contentful Paint on typical phone connections exceeded four seconds.

The team routes all product images through an image CDN, defines six width steps from 320 to 1,600 pixels, enables automatic AVIF and WebP selection and sets quality to a perceptual target. Templates now emit srcset attributes pointing at those presets, and URLs are signed so no other widths can be requested. After rollout, the typical listing thumbnail drops from about 3 MB to around 40-70 KB, and mobile LCP falls below 2.5 seconds on the same pages, with no new photos exported by hand.