Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
Create a utility that compacts HTML markup with an emphasis on whitespace and comment controls while keeping meaningful spacing intact.
<pre> and <code> untouched when preservePreformatted is enabled. @testkeepConditional is true. @testkeepComments is true, even if other removal options are enabled. @testpreserveTags while still collapsing whitespace elsewhere in the document. @test@generates
/**
* Returns a compacted HTML string using whitespace and comment controls.
* @param {string} html - Raw HTML markup to minify.
* @param {Object} [options]
* @param {boolean} [options.preservePreformatted] - Keep whitespace inside <pre> and <code> blocks.
* @param {boolean} [options.keepConditional] - Preserve conditional comments while removing ordinary comments.
* @param {boolean} [options.keepComments] - Retain all comments verbatim.
* @param {string[]} [options.preserveTags] - Tag names whose contents should retain original spacing.
* @returns {string}
*/
export function compressHtml(html, options);Provides HTML minification capabilities focused on whitespace and comment controls.
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