Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
Build a small library that minifies HTML fragments while exposing parsing controls. The caller should be able to choose whether parsing tolerates malformed markup, whether custom tag/attribute casing is preserved, and which nonstandard script types are processed.
<div><span></div>, strict mode rejects with a parsing error that names the offending tag. @test<My-Widget DATA-ID="A1">) must be preserved in the minified output. @testtype attribute appears in an allowlist are minified; other script blocks are emitted exactly as provided, including whitespace. @test@generates
/**
* Minifies HTML with configurable parsing behavior.
* @param {string} html - Input HTML fragment.
* @param {Object} [options]
* @param {boolean} [options.tolerant=false] - Whether to continue when parse errors are encountered.
* @param {boolean} [options.caseSensitive=false] - Whether to preserve tag and attribute casing.
* @param {string[]} [options.allowedScriptTypes=[]] - Script MIME types whose contents should be minified.
* @returns {Promise<string>} Resolved with the minified HTML that reflects the chosen parse-mode controls.
*/
export function minifyFragment(html, options);Provides HTML minification with configurable parsing modes.
Install with Tessl CLI
npx tessl i tessl/npm-html-minifierdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9