summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff/minify/v2/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff/minify/v2/README.md')
-rw-r--r--vendor/github.com/tdewolff/minify/v2/README.md9
1 files changed, 9 insertions, 0 deletions
diff --git a/vendor/github.com/tdewolff/minify/v2/README.md b/vendor/github.com/tdewolff/minify/v2/README.md
index 51917f776..d2bfff407 100644
--- a/vendor/github.com/tdewolff/minify/v2/README.md
+++ b/vendor/github.com/tdewolff/minify/v2/README.md
@@ -59,6 +59,7 @@ Please see https://www.patreon.com/tdewolff for ways to contribute, otherwise pl
- [Custom minifier](#custom-minifier-example)
- [ResponseWriter](#responsewriter)
- [Templates](#templates)
+ - [FAQ](#faq)
- [License](#license)
### Roadmap
@@ -717,6 +718,14 @@ Example usage:
templates := template.Must(compileTemplates("view.html", "home.html"))
```
+## FAQ
+### Newlines remain in minified output
+While you might expect the minified output to be on a single line for it to be fully minified, this is not true. In many cases, using a literal newline doesn't affect the file size, and in some cases it may even reduce the file size.
+
+A typical example is HTML. Whitespace is significant in HTML, meaning that spaces and newlines between or around tags may affect how they are displayed. There is no distinction between a space or a newline and they may be interchanged without affecting the displayed HTML. Remember that a space (0x20) and a newline (0x0A) are both one byte long, so that there is no difference in file size when interchanging them. This minifier removes unnecessary whitespace by replacing stretches of spaces and newlines by a single whitespace character. Specifically, if the stretch of white space characters contains a newline, it will replace it by a newline and otherwise by a space. This doesn't affect the file size, but may help somewhat for debugging or file transmission objectives.
+
+Another example is JavaScript. Single or double quoted string literals may not contain newline characters but instead need to escape them as `\n`. These are two bytes instead of a single newline byte. Using template literals it is allowed to have literal newline characters and we can use that fact to shave-off one byte! The result is that the minified output contains newlines instead of escaped newline characters, which makes the final file size smaller. Of course, changing from single or double quotes to template literals depends on other factors as well, and this minifier makes a calculation whether the template literal results in a shorter file size or not before converting a string literal.
+
## License
Released under the [MIT license](LICENSE.md).