htmlnano

Modular HTML minifier, built on top of the PostHTML

MIT 43 个版本
安装
npm install htmlnano
yarn add htmlnano
pnpm add htmlnano
bun add htmlnano
README

htmlnano logo htmlnano

npm version CI

Modular HTML minifier, built on top of the PostHTML. Inspired by cssnano.

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);
    });

Also, you can use it as CLI tool:

node_modules/.bin/htmlnano --help

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

Benchmarks

Website Source (KB) html-minifier-terser html-minifier-next htmlnano minify minify-html
alistapart.com 63 7.6% 11.6% 34.6% 11.1% 8.6%
developer.mozilla.org 109 38.0% 41.7% 52.8% 40.1% 39.9%
css-tricks.com 11 8.2% 34.1% 37.2% 18.8% 8.5%
en.wikipedia.org 224 4.5% 7.4% 7.2% 60.6% 2.9%
github.com 546 3.0% 9.7% 16.7% 7.3% 5.7%
edri.org 80 7.7% 12.3% 30.6% 12.3% 8.2%
leanpub.com 251 1.3% 6.9% 6.3% 6.0% 1.7%
stackoverflow.blog 139 3.9% 5.7% 7.0% 4.6% 4.7%
html.spec.whatwg.org 149 -3.9% 0.7% -2.6% 0.3% 0.2%
eff.org 54 8.8% 14.7% 10.9% 13.4% 9.7%
apple.com 229 8.9% 12.5% 11.5% 10.4% 9.5%
w3.org 50 19.0% 24.6% 23.4% 24.4% 20.3%
mastodon.social 37 3.4% 6.8% 14.6% 5.9% 3.6%
bbc.co.uk 694 0.8% 6.3% 5.9% 4.7% 1.2%
un.org 151 14.2% 22.5% 41.2% 20.0% 15.0%
lafrenchtech.gouv.fr 152 13.2% 17.9% 64.1% 17.0% 13.8%
sitepoint.com 497 0.8% 7.4% 12.9% 6.1% 0.9%
faz.net 1572 3.4% 8.0% 15.8% 4.8% 3.6%
weather.com 2395 0.3% 11.4% 18.1% 11.0% 0.6%
tc39.es 7254 8.5% 11.3% 9.3% 9.5% 9.1%
home.cern 151 37.1% 46.4% 40.2% 38.9% 39.5%
Avg. minify rate 9.0% 15.2% 21.8% 15.6% 9.9%

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

版本列表
3.3.2 2026-05-21
3.3.1 2026-05-17
3.3.0 2026-05-16
3.2.1 2026-04-20
3.2.0 2026-03-01
3.1.0 2026-02-03
3.0.0 2025-12-22
2.1.5 2025-09-19
2.1.4 2025-09-05
2.1.3 2025-09-03
2.1.2 2025-04-30
2.1.1 2024-04-28
2.1.0 2023-10-19
2.0.4 2023-04-15
2.0.3 2022-11-13
2.0.2 2022-04-06
2.0.1 2022-04-04
2.0.0 2022-01-12
1.1.1 2021-09-19
1.1.0 2021-09-19
1.0.1 2021-09-11
1.0.0 2021-04-17
0.2.9 2021-04-11
0.2.8 2020-11-15
0.2.7 2020-10-17
0.2.6 2020-07-15
0.2.5 2019-11-09
0.2.4 2019-07-11
0.2.3 2019-02-14
0.2.2 2019-01-03
0.2.1 2018-12-01
0.2.0 2018-09-14
0.1.10 2018-08-03
0.1.9 2018-04-29
0.1.8 2018-04-17
0.1.7 2018-03-13
0.1.6 2017-06-27
0.1.5 2016-04-24
0.1.4 2016-02-16
0.1.3 2016-02-09
0.1.2 2016-02-07
0.1.1 2016-01-31
0.1.0 2016-01-18