-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior when minifying HTML containing SVG #80
Comments
Related issue: kangax/html-minifier#1092. |
See terser/html-minifier-terser#80. In short, the HTML minifier strips empty SVG elements, thus breaking equations. This is not desired.
Since this is documented, can be tested on https://terser.org/html-minifier-terser/ and there is also a way to prevent all optimizations (https://github.com/terser/html-minifier-terser#ignoring-chunks-of-markup) I'm closing this issue. There are good reasons why all optimizations are disabled by default and why this is in red:
|
Ignoring chunks of markup is fine, so long as you are authoring the HTML in question. Otherwise, one needs to dynamically modify the received markup in order to preserve empty elements in SVG. |
True. Normally this is done in webpack setups with the right plugins which replace texts or before compilation using In general this case is currently not covered by the tests as it is not recommended to enable So far only html elements are not affected by this: https://github.com/terser/html-minifier-terser/blob/v6.0.2/src/htmlminifier.js#L429 I'm not sure if it makes sense to add svg and xml elements to this function by default but this could lead to the case, that we will have to add many more tags to this function to prevent such issues and that this has to be correctly tested. But as this is marked as red / breaking, I'm opting for keeping as it is and removing the option from the CLI like you already did. If this is not in your interest, you may want to check https://github.com/tdewolff/minify#html |
Thanks for the details and links. :) |
Given the following SVG (derived from this HTML document)
the minifier generates the following (derived from this HTML document)
As can be observed in the output, all the
<path>
,<rect>
, and<use>
elements have been removed from the original SVG, which is not desirable.The output was generated via the following command:
This is potentially due to the use of non-self-closing tags and
--remove-empty-elements
?If so, this may not be desirable for SVG, where "empty" elements are fairly commonplace and valid. If the minifier is unable to modify its behavior, may be worth noting in the package README that, if HTML includes SVG, may not want to use
--remove-empty-elements
.The text was updated successfully, but these errors were encountered: