Skip to content

posthtml/htmlnano

Repository files navigation

htmlnano

npm version CI

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 166 3.3% 3.3% 8.3% 4.6% 4.0%
github.com 541 3.7% 3.7% 18.1% 7.9% 6.2%
en.wikipedia.org 220 4.6% 4.6% 4.9% 6.2% 2.9%
npmjs.com 460 0.5% 0.5% 0.9% 3.6% 0.7%
tc39.es 7198 8.5% 8.5% 8.7% 9.5% 9.1%
apple.com 190 7.6% 7.6% 12.1% 10.5% 8.1%
w3.org 49 18.9% 18.9% 23.0% 24.1% 19.9%
weather.com 1770 0.2% 0.2% 12.1% 11.9% 0.6%
Avg. minify rate 5.9% 5.9% 11.0% 9.8% 6.4%

Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).

Documentation

https://htmlnano.netlify.app

Usage

npm install htmlnano
const 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);
    });

More usage examples (PostHTML, Gulp, Webpack): https://htmlnano.netlify.app/next/usage

About

Modular HTML minifier, built on top of the PostHTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 24