Minify HTML

Minify the HTML code of your pages.

Options

extensions object

File extensions to minify

Default:
[ ".html" ]
options object

Default options for minify-html library

do_not_minify_doctype boolean

Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant.

Default:
true
ensure_spec_compliant_unquoted_attribute_values boolean

Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification.

Default:
true
keep_closing_tags boolean

Do not omit closing tags when possible.

Default:
false
keep_html_and_head_opening_tags boolean

Do not omit <html> and <head> opening tags when they don't have attributes.

Default:
false
keep_spaces_between_attributes boolean

Keep spaces between attributes when possible to conform to HTML standards.

Default:
true
keep_comments boolean

Keep all comments.

Default:
false
keep_ssi_comments boolean

Keep SSI comments.

preserve_brace_template_syntax boolean

When {{, {#, or {% are seen in content, all source code until the subsequent matching closing }}, #}, or %} respectively gets piped through untouched.

preserve_chevron_percent_template_syntax boolean

When <% is seen in content, all source code until the subsequent matching closing %> gets piped through untouched.

minify_js boolean

If enabled, content in <script> tags with a JS or no MIME type will be minified using minify-js.

minify_css boolean

If enabled, CSS in <style> tags and style attributes will be minified.

remove_bangs boolean

Remove all bangs.

Default:
false
remove_processing_instructions boolean

Remove all processing_instructions.

Default:
false

Description

The MinifyHTML plugin minifies the HTML code of your pages using the minify-html minifier. It can also minify CSS and JavaScript code.

Installation

Import this plugin in your _config.ts file to use it:

import lume from "lume/mod.ts";
import minifyHTML from "lume/plugins/minify_html.ts";

const site = lume();

site.use(minifyHTML(/* Options */));

export default site;

Configuration

This plugin accepts a configuration object. The available options are:

  • extensions: An array with the extensions of the files that will be minified. By default it is [".html"].
  • options: An object with the available options for minify-html.

If you need to minify CSS and / or JS files, it's recommended that you use plugins specifically for those instead, like LightningCSS and Terser respectively.