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

HTML Output Minifier with Ignore Rules

Create a helper that minifies HTML while preserving sections called out by ignore markers and caller-supplied patterns. The goal is to ensure markup compression happens everywhere except in explicitly protected fragments or directive comments.

Capabilities

Respects inline ignore blocks

  • Input wrapped between <!-- htmlmin:ignore --> markers remains byte-for-byte, while surrounding markup is collapsed to a single-line string: <div><!-- htmlmin:ignore --><pre> keep spacing </pre><!-- htmlmin:ignore --><span>compress me</span></div> @test

Preserves templating fragments

  • When provided an ignore pattern such as /{{[^}]+}}/, templating placeholders like {{ user.name }} are preserved exactly and the rest of the document is minified into a single line. Example output: <section><h1>{{ user.name }}</h1><p>Hi there!</p></section> @test

Keeps directive comments by pattern

  • Directive comments that match caller-supplied patterns (e.g., server-side includes) stay in the output even when other comments are stripped, while surrounding markup is minified: <body><!--#include file="nav.html" --><main><p>Hi</p></main></body> @test

Optional trimming around preserved fragments

  • When trimming is enabled, whitespace immediately adjacent to preserved fragments is collapsed so that <div>\n {{slot}}\n <span> keep </span>\n</div> becomes <div>{{slot}}<span> keep </span></div> while the preserved fragment text itself is unchanged @test

Implementation

@generates

API

export type IgnorePattern = RegExp | string;

export interface IgnoreMinifyOptions {
  html: string;
  ignoredFragments?: IgnorePattern[];
  ignoredComments?: IgnorePattern[];
  collapseWhitespace?: boolean;
  trimAroundIgnores?: boolean;
}

export function minifyWithIgnores(options: IgnoreMinifyOptions): string;

Dependencies { .dependencies }

html-minifier { .dependency }

Provides HTML minification while honoring ignore markers and configurable fragment/comment preservation.

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json