HTML Minifier Builder (@now/html-minifier)

Status: Stable

This builder optimizes .html files using html-minifier.

When to Use It

When you want your HTML source files to be minified so they are as small as possible (without any semantic changes) in production.

How to Use It

We'll define a index.html file:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>
  <body>
    <h3>This is very long</h3>
  </body>
</html>

Then we'll define our build step to optimize our images:

{
  "version": 2,
  "builds": [{ "src": "*.html", "use": "@now/html-minifier" }]
}

When we deploy with now, the resulting deployment URL will be live as https://htmlproject-b2u4218wj.now.sh.

Next, use curl to query the deployment URL, you will notice the HTML has been compressed:

curl https://htmlproject-mf0azp0cg.now.sh/
<!doctype html><html lang=en><meta charset=UTF-8><title>Document</title><h3>This is very long</h3>

The example deployment above is open-source and you can view the code for it here: https://htmlproject-b2u4218wj.now.sh/_src.

Technical Details

Entrypoint

The entrypoint is always a .html file you want to optimize.