htmlnano
v3.1.0
Published
Modular HTML minifier, built on top of the PostHTML
Readme
Modular HTML minifier, built on top of the PostHTML. Inspired by cssnano.
Benchmarks
| Website | Source (KB) | html-minifier-terser | html-minifier-next | htmlnano | minify | minify-html | | ------------------------------------------------------------- | ----------: | ---------------------: | -------------------: | ---------: | --------: | ------------: | | stackoverflow.blog | 142 | 3.7% | 32.3% | 6.8% | 4.5% | 4.6% | | github.com | 549 | 2.9% | 42.2% | 16.6% | 7.3% | 5.7% | | en.wikipedia.org | 218 | 4.6% | 7.7% | 7.4% | 6.2% | 2.9% | | developer.mozilla.org | 109 | 37.9% | 42.0% | 52.7% | 40.1% | 39.9% | | tc39.es | 7243 | 8.5% | 11.8% | 9.3% | 9.5% | 9.1% | | apple.com | 210 | 9.2% | 14.4% | 11.2% | 10.3% | 9.8% | | w3.org | 50 | 19.0% | 24.6% | 23.4% | 24.4% | 20.3% | | weather.com | 1960 | 0.4% | 11.2% | 19.8% | 11.6% | 0.6% | | Avg. minify rate | | 10.8% | 23.3% | 18.4% | 14.2% | 11.6% |
Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).
Documentation
https://htmlnano.netlify.app
Usage
npm install htmlnanoconst htmlnano = require('htmlnano');
const options = {
removeEmptyAttributes: false, // Disable the module "removeEmptyAttributes"
collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
};
// posthtml, posthtml-render, and posthtml-parse options
const postHtmlOptions = {
sync: true, // https://github.com/posthtml/posthtml#usage
lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
};
htmlnano
// "preset" arg might be skipped (see "Presets" section below for more info)
// "postHtmlOptions" arg might be skipped
.process(html, options, preset, postHtmlOptions)
.then(function (result) {
// result.html is minified
})
.catch(function (err) {
console.error(err);
});Also, you can use it as CLI tool:
node_modules/.bin/htmlnano --helpMore usage examples (PostHTML, Gulp, Webpack): https://htmlnano.netlify.app/next/usage
