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-1/

Parse-Mode HTML Minifier

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.

Capabilities

Strict vs tolerant parsing

  • Given malformed markup like <div><span></div>, strict mode rejects with a parsing error that names the offending tag. @test
  • The same input, when tolerant parsing is enabled, returns a minified string instead of throwing. @test

Case-sensitive handling

  • When case-sensitive parsing is enabled, custom element and attribute casing (e.g., <My-Widget DATA-ID="A1">) must be preserved in the minified output. @test

Selective script processing

  • Only inline scripts whose type attribute appears in an allowlist are minified; other script blocks are emitted exactly as provided, including whitespace. @test

Implementation

@generates

API

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

Dependencies { .dependencies }

html-minifier { .dependency }

Provides HTML minification with configurable parsing modes.

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json