### Node.js: Install Package Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html/README.md Install the @minify-html/node package for Node.js using either npm or Yarn. ```bash npm i @minify-html/node ``` ```bash yarn add @minify-html/node ``` -------------------------------- ### Install Deno Package Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html-onepass-python/README.md Add the package to your Deno project using the JSR registry. ```bash deno add jsr:@minify-html/deno ``` -------------------------------- ### CLI minhtml Command Usage Source: https://context7.com/wilsonzlin/minify-html/llms.txt Examples of using the minhtml CLI tool for single-file minification, stdin/stdout piping, and parallel batch processing. ```bash # Install via Cargo cargo install minhtml # Minify a single file with output minhtml --output /path/to/output.min.html --keep-closing-tags --minify-css /path/to/src.html # Minify from stdin to stdout cat index.html | minhtml --minify-js --minify-css > index.min.html # Parallel batch processing (modifies files in place) minhtml --keep-closing-tags --minify-css /path/to/**/*.html # Full configuration example minhtml \ --minify-js \ --minify-css \ --minify-doctype \ --allow-removing-spaces-between-attributes \ --remove-processing-instructions \ --preserve-brace-template-syntax \ --output dist/index.html \ src/index.html ``` -------------------------------- ### Content elements whitespace example Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html/README.md Demonstrates whitespace trimming and collapsing in content elements like paragraphs. ```html
↵ ··Hey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1]↵
``` -------------------------------- ### Script tag parsing examples Source: https://github.com/wilsonzlin/minify-html/blob/master/notes/Script data.md Various scenarios showing how script tags and HTML comments interact during parsing. ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` ```html ``` -------------------------------- ### Deno/WASM API Usage Source: https://context7.com/wilsonzlin/minify-html/llms.txt This snippet demonstrates how to initialize the WASM module and minify HTML content using the Deno/WASM binding. It includes an example with various configuration options and a helper function for repeated use. ```APIDOC ## Deno/WASM API - @minify-html/deno The Deno/WASM binding requires initialization before use and works with Uint8Array data. ```typescript import init, { minify } from "@minify-html/deno"; // For WASM in browser: import init, { minify } from "@minify-html/wasm"; const encoder = new TextEncoder(); const decoder = new TextDecoder(); // Initialize the WASM module (required before first use) await init(); const html = `Card content goes here.
Card content goes here.
Hello, world!
"), { keep_spaces_between_attributes: true, keep_comments: true })); ``` -------------------------------- ### Collapse whitespace example Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html/README.md Reduces sequences of whitespace characters in text nodes to a single space. ```html↵ ··The·quick·brown·fox↵ ··jumps·over·the·lazy↵ ··dog.↵
``` ```html·The·quick·brown·fox·jumps·over·the·lazy·dog.·
``` -------------------------------- ### HTML Whitespace Collapse Example Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html-onepass-python/README.md Demonstrates how sequences of whitespace characters in text nodes are reduced to a single space. This method applies to most elements, excluding whitespace-sensitive ones. ```htmlThe·quick·brown·fox jumps·over·the·lazy dog.
``` ```htmlThe·quick·brown·fox·jumps·over·the·lazy·dog.
``` -------------------------------- ### Destroy whole whitespace example Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html/README.md Removes text nodes between tags that consist only of whitespace. ```html↵ ··Hey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1]↵
``` ```htmlHey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1]
``` -------------------------------- ### Attribute Name Character Set Source: https://github.com/wilsonzlin/minify-html/blob/master/notes/Parsing.md An attribute name can start with any character except whitespace, `/`, or `>`. The `=` character is permitted within the name. The name continues until the next `=`, `/`, `>`, or whitespace. ```html == "a": {}#$'=/> ``` -------------------------------- ### Interpreting Literal '<' in Content Source: https://github.com/wilsonzlin/minify-html/blob/master/notes/Parsing.md If a `<` character in the content is not followed by an alphanumeric, `:`, or `=` character, it is treated as a literal character, not the start of a tag. ```htmlHey,·I·just·found out·about·this·cool·website! [1]
``` ```htmlHey,·I·just·found out·about·this·cool·website! [1]
``` -------------------------------- ### Handling Malformed Script/Textarea Tags Source: https://github.com/wilsonzlin/minify-html/blob/master/notes/Parsing.md Special tags like script, style, textarea, and title do not close until a case-insensitive `` followed by the tag name is encountered. This example shows how variations in casing are handled. ```html ``` -------------------------------- ### Collapse Whitespace in Paragraphs Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html-python/README.md Whitespace within paragraph tags is collapsed. This example shows the 'before' and 'after' states of a paragraph with emphasis tags. ```htmlHey,·just·found·out·about·this·cool·website!·[1]
``` -------------------------------- ### HTML Whitespace Destruction Example Source: https://github.com/wilsonzlin/minify-html/blob/master/minify-html-onepass-python/README.md Illustrates the removal of text nodes that consist solely of whitespace characters between tags. This is applicable to elements that are not whitespace-sensitive, content, content-first, or formatting elements. ```htmlHello, world!
", cfg); ``` -------------------------------- ### Configuration Options Reference Source: https://context7.com/wilsonzlin/minify-html/llms.txt This section details all available configuration options for the minify-html library, controlling various aspects of the HTML minification process. ```APIDOC ## Configuration Options Reference All configuration options control minification behavior. All options default to `false`. ```typescript interface MinifyConfig { // Minification options minify_js: boolean; // Minify JavaScript in