HTML Minior

Last modified on

HTML Minior is a tool to minify or compress your HTML code.

By default, it implements this trimming method:

function minifyHTML(html) {
    return (
        html
            // Removes HTML comments.
            .replace(/<!--[\s\S]*?-->/g, "")
            // Collapses all whitespace (spaces, newlines, tabs) into single spaces.
            .replace(/\s+/g, " ")
            // Removes spaces between tags.
            .replace(/>\s+</g, "><")
            // Trims leading-trailing whitespace.
            .trim()
    )
}

Compress CSS

If checked (picked), it will implement CSSO package to accomplish CSS code minification within HTML code which is wrapped in style tag.

Compress JS

If checked (picked), it will implement Terser package to accomplish JavaScript code minification within HTML code which is wrapped in script tag. The code mangling is inner scope only and it automatically converts the Unicode character from the JavaScript code to Unicode escape sequence.