Skip to main content

minify_html_template

Function minify_html_template 

Source
pub fn minify_html_template(html: &str) -> String
Expand description

Strips redundant whitespace from an HTML template string while preserving the verbatim contents of <script> and <style> blocks.

Unlike a full HTML parser, this is a single-pass character-level state machine tuned for the two euv index templates (INDEX_HTML_DEV / INDEX_HTML_RELEASE):

  • HTML comments (<!-- ... -->) are removed.
  • Whitespace between tags (>...<) collapses to nothing when the whitespace is purely indentation / newlines, and to a single space otherwise (preserving word boundaries inside text nodes).
  • Inside <tag ...> attributes, runs of whitespace collapse to one space, but <pre> / <textarea> / quoted attribute values are not handled — the euv templates do not use those.
  • <script> and <style> content is copied byte-for-byte; the inline JS / CSS inside is never touched by this pass (minify_inline_js_snippets already handled the wasm-bindgen snippets, and the dev-only reload script is intentionally readable).

The output is safe to feed directly to the browser; it differs from the source only in whitespace and the presence of comments.

§Arguments

  • &str - The HTML template (after placeholder replacement).

§Returns

  • String - The minified HTML.