How do I use SlashImage with a CDN?

2 min read · Last updated June 2026

Use Picture tag delivery, the plugin's default. Each format is its own file at its own URL, so any CDN can cache them all correctly with no extra configuration. After a bulk optimization, purge your CDN cache so it picks up the new files.

SlashImage creates and optimizes your image files; your CDN serves them. SlashImage does not manage or configure your CDN.

Why Picture tag is CDN-safe

With Picture tag mode, each format is a separate file at a separate URL: photo.jpg, photo.jpg.webp, and photo.jpg.avif. Each visitor's browser requests the URL for its supported format, and your CDN caches each file independently. No header negotiation is involved, so it works on any CDN by default.

Server rewrite does not work this way. Server rewrite serves different image bytes from the same URL depending on each visitor's Accept header. For a CDN to serve different formats correctly from one URL, it must vary its cache on that header — and most CDNs do not do this by default:

  • Cloudflare ignores Vary: Accept by default, caching one format per URL.
  • BunnyCDN caches by path only and ignores the origin Vary header by default.
  • KeyCDN does not honor Vary: Accept automatically.
  • Fastly is an exception that honors the standard Vary response header.

If you must use server rewrite (for example, to cover CSS background images), some CDNs offer a setting to vary the cache on the Accept header. Check your CDN's documentation for whether it supports this.

For Cloudflare specifically, see Why doesn't server rewrite work behind Cloudflare?.

Clear your cache after optimizing

When SlashImage optimizes or restores an image, it replaces the file on disk. Your CDN and any page cache may keep serving the previous version until their stored copy expires. After a bulk run, a re-optimize, or a restore, purge your CDN and page cache so visitors get the updated files.

What can go wrong

  • Visitors still see the old image after optimizing. Your CDN or page cache is serving a stale copy. Purge both.
  • The wrong format reaches some browsers. You are likely using Server rewrite behind a CDN. Switch to Picture tag.

See also

Was this helpful?