Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
Transforms raw HTML into a lean document or fragment by pruning optional tags and normalizing doctypes for embeddable output.
<!doctype html> at the top of the output, preserving the remaining markup. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> becomes the short form while keeping content intact. @test<html>, <head>, and <body> when they only provide default containers and have no attributes, keeping head resources before body content in the resulting string. @test<div> or <section> when they have no children and no attributes, while preserving empty elements in a keep list (script, style, meta, link, img, br, hr). @test<html> or <body> tags, returns a trimmed fragment without inserting default wrappers, while still collapsing redundant whitespace and removing optional closing tags inside the fragment. @test@generates
// Accepts raw HTML as a string and returns pruned HTML as a string.
export function pruneMarkup(html);Used to perform tag pruning, doctype normalization, and fragment-safe minification.
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