opyeb SVGForge

Guides · Delivery

SVG and text compression: what gzip and Brotli really save

Updated 28 Nov 2026 · 8 min read

SVG is text, so it belongs with HTML and CSS in the compression story, not with PNG and JPEG. A well-configured server sends it with gzip or Brotli and the browser decompresses it transparently. A misconfigured one sends it raw, and a 40 KB icon sprite arrives as 40 KB of XML on every cold cache visit.

Compression ratios depend on repetition. Tag names, attribute names and repeated path commands are highly repetitive, so an unoptimised file can compress to 20% of its size. An optimised file with unique short strings compresses less in percentage terms but still ends smaller. This is why a tool that reports only the optimisation percentage and not the compressed size can mislead.

ContentTypical gzip ratioTypical Brotli ratioNote
Unoptimised editor export15–25% of original12–20%Lots of repetition to exploit
Optimised SVG30–45% of original25–40%Smaller start, smaller end
URL-encoded data URI in CSS30–50%25–45%Tag names remain readable
Base64 data URI70–90%65–85%Dense alphabet, little repetition
SVG with embedded raster95–100%95–100%Already compressed pixels

Headers that matter

Serve SVG as image/svg+xml. A server that sends text/plain or application/octet-stream breaks rendering through <img> in some browsers and prevents compression rules keyed on MIME type from matching. Add Vary: Accept-Encoding when compression is negotiated, and give the file a long cache lifetime with a content hash in the name if it is part of a build.

For inline SVG in HTML there is nothing extra to configure: the page's compression covers it. For a sprite, cache it for a year and version the filename; a sprite that changes weekly should not be cached for a year without a hash. For icons served from a CDN, check that the CDN compresses SVG; many do by default, but not all.

When minification matters more

If a file is served only once and is small, the difference between minified and not is a few hundred bytes, and the effort may not pay. If the file is in a build artefact used by thousands of sessions, every byte is multiplied. The general rule is to optimise what is cached and reused, and to leave one-off files alone if the process is fragile.

There is also a maintenance cost. A minified SVG is hard to review and impossible to edit by hand. Keep the readable source in the repository and generate the minified file during the build, so a change is visible in the source diff and the deployed artefact stays small.

Do not embed a large raster image inside an SVG to keep it as one file. The SVG wrapper adds bytes and the raster is already compressed, so the result is larger than the original image and loses the vector benefits entirely.

Compression settings also interact with caching. A file compressed at a high level but served with a short cache lifetime is re-downloaded and re-decompressed repeatedly, which costs more than a slightly larger file cached for a year.

Sources

Questions

Is SVG compressed automatically?

Only if the server compresses it. SVG is XML text, so gzip and Brotli work well, but a static host must be configured to compress image/svg+xml. Many hosts compress HTML, CSS and JavaScript by default and forget SVG because its MIME type starts with image/.

Why does a Base64 data URI not compress well?

Base64 encodes binary-looking data as a dense alphanumeric string with little repetition, and gzip works by finding repetition. The same SVG URL-encoded keeps its tag names and attributes readable, so it compresses far better. This is one more reason to prefer URL encoding in CSS.

Does a smaller SVG always transfer less?

Not necessarily. Two files that differ by 20% before compression can differ by 5% after gzip, because the smaller file has less repetition to exploit. Measure the compressed size on the wire, not only the file size on disk.

The optimizer reports UTF-8 bytes; compare that number with the compressed size your server sends.

Open the optimizer

Written against the W3C SVG specifications, MDN and the React and WCAG documentation; every sample in the examples can be pasted into the optimizer linked above.

Back to the guides