Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
A utility that trims HTML responses by cleaning up redundant or empty attributes while leaving tag structure and content untouched.
Only attribute tokens should change; tag order, inner text, and spacing between elements should remain as provided.
<script type="text/javascript" async="" src="/app.js"></script><link rel="stylesheet" type="text/css" href="/styles.css"> becomes <script async src=/app.js></script><link rel=stylesheet href=/styles.css>. @testdisabled="disabled") are reduced to the bare attribute while keeping non-boolean attributes intact. @testid=main and title="hero section" co-exist in the same node. @test@generates
export interface CleanupOptions {
/**
* When true, drops empty attribute declarations; defaults to true.
*/
removeEmpty?: boolean;
/**
* When true, collapses boolean attributes to bare names; defaults to true.
*/
collapseBooleans?: boolean;
/**
* When true, removes quotes when safe and keeps them when required; defaults to true.
*/
trimQuotes?: boolean;
}
/**
* Cleans HTML attribute usage while leaving tag structure and text content unchanged.
* @param html Raw HTML string to process.
* @param options Optional toggles controlling attribute cleanup behaviors.
*/
export function cleanAttributes(html: string, options?: CleanupOptions): string;Provides HTML minification primitives for attribute cleanup (empty attributes, redundant defaults, boolean collapsing, safe quote removal).
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