Cache-Control and CDN Strategies for Images — Technical Guide


cache control image caching cdn images http cache cache headers max-age

Cache-Control and CDN Strategies for Images — Technical Guide

Effective caching reduces latency and bandwidth. This guide covers HTTP cache headers for images and practical CDN strategies.

Key Cache Headers

Cache-Control

Cache-Control: max-age=31536000, public, immutable
  • max-age — How long the response is fresh (seconds). 31536000 = 1 year.
  • public — Can be cached by browsers and CDNs (e.g. for shared/public responses).
  • immutable — Tells caches the resource won’t change during max-age; no revalidation until it expires.
  • private — Only the browser may cache (e.g. user-specific content).
  • no-store — Do not store the response (e.g. very dynamic content).
  • no-cache — Store, but revalidate before using (often misinterpreted; “no store” is different).

ETag and Last-Modified

Used for conditional requests (304 Not Modified):

ETag: "abc123"
Last-Modified: Wed, 13 Mar 2026 12:00:00 GMT

Browser sends If-None-Match or If-Modified-Since; server returns 304 when unchanged.

Strategies by Image Type

Immutable / versioned assets

Filenames include a hash or version (e.g. logo.abc123.png). Safe to cache long:

Cache-Control: public, max-age=31536000, immutable

User uploads (e.g. avatars, galleries)

  • If URL changes when content changes (e.g. /i/abc123.jpg), moderate cache is fine:
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
  • max-age=86400 (1 day): fresh for a day.
  • stale-while-revalidate=604800 (7 days): serve stale while revalidating in the background.

Dynamic / personalized images

  • Short cache or no-store:
Cache-Control: private, max-age=60

or for highly dynamic:

Cache-Control: no-store

CDN Considerations

Purge and invalidation

  • CDNs cache based on URL. Changing the URL (e.g. with a query ?v=2 or path /v2/) bypasses old cache.
  • Purge APIs let you invalidate by URL or path when you know an image changed.

Edge caching

  • Set long max-age for immutable URLs.
  • Use stale-while-revalidate to improve perceived speed while revalidating.
  • Ensure Vary is correct if responses differ (e.g. by Accept for WebP vs JPEG).

Typical CDN config (conceptual)

# Static, versioned images
/images/*.png, *.jpg, *.webp
  Cache-Control: public, max-age=31536000, immutable

# User content (URL changes on update)
/i/*
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800

Versioning

To avoid long-lived caches serving old images:

  1. Query string: image.jpg?v=20260313
  2. Path: /v/20260313/image.jpg
  3. Hash in filename: image.a1b2c3d4.jpg

Hash in filename gives the longest safe cache and clear invalidation when the file changes.

Served by ImageUpload.app

When using an image host or CDN (including ImageUpload.app), check which headers they send. For permanent URLs (e.g. content-addressed), long max-age + immutable is ideal; for updatable images, shorter max-age and stale-while-revalidate are common.

Conclusion

  • Immutable, versioned images: max-age=31536000, immutable.
  • User content with stable URLs: max-age=86400, stale-while-revalidate=604800.
  • Dynamic content: Short cache or no-store.
  • Use URL versioning or hashes to avoid serving stale content.

Host and share images with direct links: ImageUpload.app

Fri Mar 13 2026 00:00:00 GMT+0000 (Coordinated Universal Time)