Java, Web

Delivering compressed SVG format(SVGZ) using Spring Boot

SVG stands for Scalable Vector Graphics. Literally, it’s a graphic format that is scalable, jaggy free  and compact (in most cases).
Most draw tools natively support loading and saving SVG files. You’ll find the format useful when you’re annoyed with jaggy images on your corporate web site.

Today I replaced a png logo on our internal system with an SVG file.

The file size was supposed to be shrunk, but the truth is that it grew from 18.26kb to 431kb. Then I was reminded of the compressed SVG format which Illustrator is offering. And the file size got minified to 3,688 bytes.

But it doesn’t get rendered correctly.

It tuns out that Spring Boot and the Web server do not specify the Content-Encoding header to gzip OOTB.

Serving compressed SVG files

I might be able to configure that on Nginx side, but in order to get the image loaded correctly on my local environment as well, I implemented a very simple ServletFilter.

And now it works 🙂


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です