CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-html-minifier

Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options

86

1.17x
Overview
Eval results
Files

task.mdevals/scenario-2/

HTML Whitespace and Comment Cleaner

Create a utility that compacts HTML markup with an emphasis on whitespace and comment controls while keeping meaningful spacing intact.

Capabilities

Collapse redundant spacing

  • Converts repeated spaces, tabs, and newlines between block-level tags into a single space without altering text content. @test
  • Leaves whitespace inside <pre> and <code> untouched when preservePreformatted is enabled. @test

Comment handling

  • Removes ordinary HTML comments while keeping IE-style conditional comments when keepConditional is true. @test
  • Keeps all comments when keepComments is true, even if other removal options are enabled. @test

Custom tag preservation

  • Skips whitespace collapsing inside any tag names listed in preserveTags while still collapsing whitespace elsewhere in the document. @test

Implementation

@generates

API

/**
 * 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);

Dependencies { .dependencies }

html-minifier { .dependency }

Provides HTML minification capabilities focused on whitespace and comment controls.

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json