HTML-minifier is a highly configurable, well-tested, JavaScript-based HTML minifier. It serves the primary function of reducing the size of your HTML files by eliminating unnecessary white spaces, comments, and other non-required elements. This reduction in size leads to faster load times and improved performance for your websites, which is beneficial for both user experience and SEO rankings.
To use html-minifier, you can install it via npm for command line application or programmatic use. Here is an example of how to install it:
# for command line use
npm install html-minifier -g
# for programmatic use
npm install html-minifier
Also, you can clone it via Git:
git clone git://github.com/kangax/html-minifier.git
cd html-minifier
npm link .
You can activate html-minifier options when running the command. Here is an example of a sample command line:
html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
For Node.js usage, see the following example:
var minify = require('html-minifier').minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
// output: '<p title=blah id=moo>foo</p>'
For detailed documentation on how to use html-minifier, options, testing results, and more, you can refer to its official GitHub page: https://github.com/kangax/html-minifier. Moreover, there is a corresponding blog post here which provides comprehensive information about the tool's working mechanism, option descriptions, and other aspects.