Go to file
Wilson Lin e15381c1cb Handle text script content 2019-12-27 21:52:49 +11:00
archive Handle text script content 2019-12-27 21:52:49 +11:00
notes Handle text script content 2019-12-27 21:52:49 +11:00
src Handle text script content 2019-12-27 21:52:49 +11:00
.gitignore Migrate mostly to Rust with significant optimisations and refactoring 2019-12-23 22:48:41 +11:00
Cargo.toml Complete initial migration to Rust 2019-12-25 20:44:51 +11:00
LICENSE Initial commit 2018-06-30 22:37:24 +12:00
README.md Fix entity decoding in attribute value; enforce valid Unicode Scalar Value numeric entity refs; update named entities; error messages for CLI; support post-minification empty attributes 2019-12-27 00:23:33 +11:00

README.md

hyperbuild

A fast one-pass in-place HTML minifier written in Rust with advanced whitespace handling.

Currently in beta, working on documentation and tests. Issues and pull requests welcome!

Features

  • Minification is done in one pass with no backtracking or DOM/AST building.
  • No dynamic memory is allocated during processing, which increases safety and performance.
  • Advanced whitespace handling options allow maximum minification while retaining valid spaces.

Usage

hyperbuild --src /path/to/src.html --out /path/to/output.min.html

Minification

Guide below is currently WIP.

Whitespace

hyperbuild has advanced whitespace minification that can allow strategies such as:

  • leave whitespace untouched in pre and code, which are whitespace sensitive
  • trim and collapse whitespace in content tags, as whitespace is collapsed anyway when rendered
  • remove whitespace in layout tags, which allows the use of inline layouts while keeping formatted code

Parsing

hyperbuild is an HTML minifier and simply does HTML minification. In addition to keeping to one role, hyperbuild almost does no syntax checking or standards enforcement for performance and code complexity reasons.

For example, this means that it's not an error to have self-closing tags, having multiple <body> elements, using incorrect attribute names and values, or using <br> like <br>alert('');</br>

However, there are some syntax requirements for speed and sanity reasons.

Tags

Tag names are case sensitive.

Entities

Well-formed entities are decoded, including in attribute values.

They are considered as a single character representing their decoded value. This means that &#9; is considered a whitespace character and could be minified.

If a named entity is an invalid reference as per the spec, it is considered malformed and will be interpreted literally.

Numeric character references that do not reference a valid Unicode Scalar Value are considered malformed.

Attributes

Backticks (`) are not valid quote marks and are not interpreted as such. However, backticks are valid attribute value quotes in Internet Explorer.

It's an error to place whitespace between = and attribute names/values.

Special handling of some attributes require case-sensitive names and values. For example, class and type="text/javascript".

It's an error if there is no whitespace before an attribute.

Most likely, the cause of this error is either invalid syntax or something like:

<div class="a"name="1"></div>

(Note the lack of space between the end of the class attribute and the beginning of the name attribute.)

Script and style

script and style tags must be closed with </script> and </style> respectively (case-sensitive).

Note that the closing tag must not contain any whitespace (e.g. </script >).

Development

Currently, hyperbuild has a few limitations:

  • Only UTF-8/ASCII is supported.
  • Not aware of exotic Unicode whitespace characters.

Patches to change any of these welcome!