Serving SVG from Cloudflare Workers
Cloudflare Workers can serve static SVGs from the edge or generate them dynamically — here's how to set up both patterns correctly.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
Serving Static SVG Assets
Static SVG files served through Cloudflare Workers Sites or from an R2 bucket benefit from Cloudflare's global edge caching automatically — set explicit `Cache-Control` headers in the Worker's response to control how aggressively the CDN and browsers cache each asset beyond Cloudflare's defaults.
- Workers Sites and R2 both serve static SVGs from the global edge
- Explicit Cache-Control headers fine-tune caching behavior
- Edge caching means near-instant delivery worldwide
Dynamic Generation and KV Storage
For personalized SVG (badges, dynamic charts, generated social cards), build the SVG as a template string within the Worker's fetch handler, optionally caching generated variants in Workers KV keyed by input parameters to avoid regenerating identical SVGs repeatedly.
- Template-string SVG generation runs directly in the Worker
- Workers KV caches generated variants by input parameter
- Avoids redundant regeneration for frequently-requested variants
Frequently Asked Questions
What's the advantage of R2 over Workers Sites for SVG assets?
R2 offers S3-compatible object storage with no egress fees, better suited to a large or growing library of SVG assets, while Workers Sites is simpler for a smaller, fixed set of static files bundled with the Worker.
How do I cache dynamically generated SVGs efficiently?
Use Workers KV or the Cache API keyed by a hash of the input parameters — if the same badge or chart is requested again with identical inputs, serve the cached SVG instead of regenerating it.
Related guides
Ready to Convert Your Image to SVG?
Free online converter — no sign-up, no watermarks, results in under 3 seconds.
Try It Free — Convert Image to SVG