-
Notifications
You must be signed in to change notification settings - Fork 32
Improve SVG encoding in data URIs #46
Comments
@steffenweber thanks, this is a really nice one. I've started to implement the advanced optimization based on that article and the postcss-svgo plugin code: https://github.com/assetsjs/assets/tree/feature/svg-data-optimization However, for now I would like to omit the quotes optimization, because they require some tricky logic: the quotes in attributes should be forced to be single, while the rest should be kept as they were (so we don’t break possible textual content inside SVG). postcss-svgo acts pretty naive in this case — it just converts every quote, so those textual contents could be spoiled. I think I'd release a new version without quote optimization and do it later. I would also appreciate any help in implementing it. |
Thank you for starting the implementation! There is a small change required to make it work because currently the generated data URIs have a syntax error (Chrome reports Bad: The alternative is easier to implement: just prepend Quote optimization: I thought that quotes appearing unencoded as General approach: For safety reasons, I think it would be better to apply
|
Hmm, maybe the proposed optimization is not such a good idea after all.
See also: https://perishablepress.com/stop-using-unsafe-characters-in-urls/ |
What about an option for custom function to encode svg like here? |
First of all, thank you for PostCSS Assets!
I think the encoding of SVGs in data URIs can be improved as described in the blog post Optimizing SVGs in data URIs. The method "Optimized URL-encoded" yields a smaller result than "Fully URL-encoded".
postcss-svgo uses the optimized URL-encoding. (But in my specific use case the SVG files have already been processed by SVGO when I pass them to PostCSS Assets. So ideally I do not want to run them through SVGO a second time.)
The text was updated successfully, but these errors were encountered: