Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options
86
Build a helper that takes an HTML string and produces an equivalent string where inline CSS and JavaScript are minified, while safely skipping templating placeholders and non-JS scripts that should remain readable.
style attributes and <style> tags, trimming redundant whitespace and semicolons without changing meaning. @test<script> blocks meant for the browser, preserving behavior. @test{{token}}, <% code %>) untouched while minifying surrounding CSS/JS. @testapplication/ld+json) unchanged while minifying supported scripts. @test@generates
/**
* Minifies inline CSS and JavaScript inside an HTML string.
* @param {string} html - The HTML to process.
* @param {{ templateFragments?: RegExp[]; skipScriptTypes?: string[] }} [options]
* @returns {string} Minified HTML with preserved templating fragments and skipped scripts.
*/
export function minifyInlineAssets(html, options = {}) {}Provides HTML, inline CSS, and inline JS 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