Spent the last 8hrs fixing the one edge case that kept breaking the image optimizer: SVGs.
The attachment is the proof. https://cdn.staticdelivr.com/img/images?url=https://staticdelivr.com/assets/sponsors/cloudflare.svg now returns as a real image instead of a text response.
Before this, the /img/images pipeline was built for raster. When you passed an SVG it would hit sharp, fail the decode, then fall back to a raw proxy with content-type: text/xml. Browsers would either download it, block it in an <img> tag, or miss the cache entirely because we were not setting immutable headers. It was especially visible on the sponsors page where Cloudflare, Hetzner, and Tuta logos would flash or 404 during a provider failover.
I added a dedicated SVG branch:
- Detect
image/svg+xmlearly and skip raster transforms - Run SVGO with a safe preset: strip scripts, comments, and editor metadata, preserve
viewBox,title, andaria-labelfor accessibility - Set correct headers:
content-type: image/svg+xml; charset=utf-8,cache-control: public, max-age=31536000, immutable, andtiming-allow-origin: * - Pipe the result into the same multi-CDN cache we use for WebP/AVIF so it hits all 577 nodes, not just Origin
That last part matters. With Fastly and Gcore both red yesterday on status.staticdelivr.com, the SVG still served at 26ms from Cloudflare because it is now treated like any other optimized image. No more special-casing in the WordPress plugin either.
This directly unblocks two things I have been wanting to ship: 1) SVG logos in the Google Fonts integration without layout shift, and 2) allowing users to pass ?w=256&format=webp on an SVG source and get a rasterized fallback for old email clients. The optimizer will now do the conversion server-side instead of failing.
Next I will add ?sanitize=0 for trusted origins and surface SVG bytes-saved in the same telemetry that powers the 142GB saved counter.
Log in to leave a comment