Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
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.
<!-- 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/{{[^}]+}}/, 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<body><!--#include file="nav.html" --><main><p>Hi</p></main></body> @test<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@generates
export type IgnorePattern = RegExp | string;
export interface IgnoreMinifyOptions {
html: string;
ignoredFragments?: IgnorePattern[];
ignoredComments?: IgnorePattern[];
collapseWhitespace?: boolean;
trimAroundIgnores?: boolean;
}
export function minifyWithIgnores(options: IgnoreMinifyOptions): string;Provides HTML minification while honoring ignore markers and configurable fragment/comment preservation.
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