1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Files
svgo/docs/03-plugins/remove-comments.mdx
Seth Falco 4c2cc1bbdb feat(inlineStyles): remove redundant presentation attrs (#1829)
SVGs can have the same presentation attribute declared redundantly in
both the node attributes and `<style>` tag.

This wouldn't break anything, but we can shave off a few more bytes by
dropping the attribute in this case.
2023-11-11 12:43:13 +00:00

56 lines
2.5 KiB
Plaintext

---
title: Remove Comments
svgo:
pluginId: removeComments
defaultPlugin: true
parameters:
preservePatterns:
description: An array of regular expressions (<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp" target="_blank">RegExp</a> or string). If the comment matches any of these, including partial matches, the comment is preserved. Set to <code>false</code> to disable this behavior and remove comments indiscriminately.
default:
- "^!"
---
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](https://fontawesome.com/license/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)](https://creativecommons.org/licenses/by/4.0/), but removing the comment would strip away that attribution.
## Usage
<PluginUsage/>
### Parameters
<PluginParams/>
## Demo
<PluginDemo/>
## Trivia
### Legal Comments
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:
* [clean-css](https://github.com/clean-css/clean-css#how-to-preserve-a-comment-block)
* [CSSO](https://github.com/css/csso#syntaxcompressast-options)
* [esbuild](https://esbuild.github.io/api/#legal-comments)
* [Sass](https://sass-lang.com/documentation/syntax/comments/)
* [Terser](https://github.com/terser/terser#keeping-copyright-notices-or-other-comments) / [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin#preserve-comments)
* [UglifyJS](https://github.com/mishoo/UglifyJS#keeping-copyright-notices-or-other-comments)
* [YUI Compressor](https://github.com/yui/yuicompressor#notes)
## Implementation
* https://github.com/svg/svgo/blob/main/plugins/removeComments.js