Back to Svgo

removeComments

docs/04-plugins/removeComments.mdx

4.0.11.8 KB
Original Source

Removes XML comments from the document.

XML comments are the content between the <!-- and --> syntax, and do not effect rendering. From an optimization perspective, these can always be safely removed.

By default, this plugin ignores legal comments, also known as "special comments" or "protected comments". These are comments that start with an exclamation point (!) and are often used for legal information like copyright notices, licensing, or attribution.

For example, the following comment can be found in Font Awesome Free icons:

svg
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->

Removing a comment like this may be considered a breach of the license terms, as Font Awesome Free is released under CC-BY-4.0 (Creative Commons Attribution), but removing the comment would strip away that attribution.

It's unclear if there are authoritative resources promoting this syntax for legal comments. However, the convention to preserve them based on this can be seen by a number of minification and build tools: