html 压缩工具 html-minifier
https://github.com/kangax/html-minifier#options-quick-reference
1、参数列表
| option | Description | Default |
| removeComments | 删除注释,但是会保留script和style中的注释 | false |
| removeCommentsFromCDATA | 从脚本和样式删除的注释 | false |
| removeCDATASectionsFromCDATA | 删除CDATA节从脚本和样式元素 | |
| collapseWhitespace | 删除空格,但是不会删除SCRIPT、style和textarea中的空格 | |
| conservativeCollapse | 删除空格,总是保留一个空格 | |
| preserveLineBreaks | ||
| collapseBooleanAttributes | 省略只有boolean值的属性值,比如:readonly checked | |
| removeAttributeQuotes |
删除引号,删除不需要引号的值。 例如: var input = '<p class="foo-bar" id="moo" title="blah blah">foo</p>'; var output = minify(input, { removeAttributeQuotes: true }); output; // '<p class="foo-bar" id=moo title="blah blah">foo</p>' |
|
| removeRedundantAttributes | 删除多余的属性 | |
| preventAttributesEscaping | ||
| useShortDoctype | 使用短的文档类型 | |
| removeEmptyAttributes | 删除空属性 | |
| removeScriptTypeAttributes | 删除script的类型属性,在h5下面script的type默认值:text/javascript | |
| removeStyleLinkTypeAttributes | 删除style的类型属性,同上 | |
| removeOptionalTags | ||
| removeIgnored | 删除指定开头和结尾的内容 以逗号分割 | |
| removeEmptyElements | 删除空元素 | |
| lint | ||
| keepClosingSlash | ||
| caseSensitive | ||
| minifyJS | 压缩js | |
| minifyCSS | 压缩css | |
| minifyURLs | 压缩url | |
| ignoreCustomComments | 忽略指定的注释内容 | |
| processScripts | ||
| maxLineLength | 指定html输出的最大列数,超过就换行显示 | |
| customAttrAssign | 允许的自定义属性列表 | |
| customAttrSurround | ||
| customAttrCollapse | 指定要换行的自定义属性(正则) |
更多可以参考作者例子:
http://perfectionkills.com/experimenting-with-html-minifier/
注:通过自己验证然后结合翻译总结的描述,有错误的地方请指正,谢谢!

浙公网安备 33010602011771号