How to Use SVG in Bun
Handle SVG files efficiently in Bun's HTTP server and bundler workflows.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
Serving SVG with Bun.serve
Bun's built-in server can read and return SVG files directly, setting the correct content type so browsers render them inline. Bun's speed makes it well suited to serving many small SVG icon requests.
- Set Content-Type: image/svg+xml on responses
- Bun.serve handles SVG file reads quickly
- Great for icon APIs needing low latency
Bundling SVG as Components
Bun's bundler can inline SVG content into JS/TS modules at build time, similar to other bundlers' SVG-to-component loaders. Convert raster logos to SVG first for clean, optimizable source files.
- Inline SVG into modules at bundle time
- Convert raster logos to SVG before bundling
- Keep source SVGs optimized for smaller bundles
Frequently Asked Questions
Does Bun.serve need a special content type for SVG?
Yes — explicitly set Content-Type: image/svg+xml in the Response object so browsers render the SVG instead of downloading it.
Can Bun import SVG files directly into code?
With the right loader configuration, Bun's bundler can inline SVG content into your JS/TS modules at build time.
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