URL rewriting, format negotiation, and caching explained.

How It Works

URL rewriting

The plugin hooks into WordPress's image rendering pipeline to rewrite URLs at three levels:

  1. Attachment URLs — Every call to wp_get_attachment_url() returns a CDN URL
  2. Responsive srcset — All srcset entries are rewritten with proper ?w= params
  3. Post content — Images embedded in post HTML are rewritten via regex

Size suffix stripping

WordPress generates resized variants like hero-1024x768.jpg. Spronta strips these suffixes and passes the original to the CDN with a ?w= parameter:

hero-1024x768.jpg → hero.jpg?w=1024&q=medium

This means Spronta resizes from the original full-res image (better quality) and can apply format negotiation (WebP/AVIF).

Format negotiation

When format is set to Auto (default), the CDN reads the browser's Accept header and serves the best supported format:

  • Chrome, Edge → AVIF or WebP
  • Safari 16.4+ → AVIF or WebP
  • Older Safari → JPEG
  • Firefox → WebP

All from the same URL — no theme changes needed.

Originals stay safe

The plugin never modifies your media library files. It only rewrites URLs at render time. Deactivate the plugin and every image instantly reverts to your original WordPress URLs.

Caching

Transformed images are cached at three levels:

  1. Edge cache — Cloudflare CDN, global PoPs, instant
  2. Variant cache — R2 storage, persists across edge evictions
  3. Quality cache — SSIMULACRA2 calibration cached per source image

The first request for a new transform triggers a WASM encode (~20-100ms). Subsequent requests are served from cache.

Compatibility

Works with:

  • Themes: Any theme that uses WordPress's standard image functions
  • Page builders: Gutenberg, Elementor, Divi, Beaver Builder, Brizy
  • E-commerce: WooCommerce product images, gallery, variations
  • Custom fields: ACF, Meta Box, Pods (image field URLs are rewritten)
  • Caching plugins: WP Super Cache, W3 Total Cache, WP Rocket, LiteSpeed Cache
  • CDN plugins: Spronta replaces the need for separate CDN plugins for images