Hugo server and .svgz

Hello,

Is there a way of displaying svgz (compressed image/svg+xml mimetype) with hugo server?

[EDIT] Post discard

I didn’t read that you want it with the hugo server and not generate the code. Sorry.

When developing using the Hugo server, I’m not aware of a way of adding this support without making modifications to Hugo.

When publishing your site, you should make sure to not use the Hugo server. Nginx is one of the popular servers, and that software allows for configuration of additional content types than those known to Nginx.

Yeah, it’s the same with Apache2. I’m explicitly telling it to recognize svgz as compressed svg (in .htaccess):

AddType image/svg+xml svgz
AddEncoding x-gzip .svgz

All right, so the best solution I could come up with for the moment is to keep svg and svgz versions of each file, and then, just before building the site, run sed to replace svg references with svgz. Finally, after the build is complete, revert this change to make hugo server show these images again, so I can see what I’m working with.

Or may be you can split/test your code with:

{{ if site.IsServer }}
   {{ partial "My_Svg_Images.html" . }}
{{ else }}
   {{ partial "My_SvgZ_Images.html" . }}
{{ end }}
3 Likes

Thanks @divinerites.
This is so much better than juggling with file references. A very handy variable.

  • If you add a new MIME type (media type) for svgz in your site config then it will be added to the server config (if you need some HTTP headers to be applied as well, that is also supported by a recent server config addition).
  • That said, if I understand it correctly, svgz is just gzipped svg, so my strategy would be to just use plain uncompressed svgs locally, then set up the gzip compression on deployment to the production server.
3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.