Pular para o conteúdo
POST AI agent ready /v1/minify/html

HTML Minify API - Strip Comments and Collapse Whitespace

Removes <!-- --> comments, collapses whitespace between tags to a single space, removes internal whitespace runs, drops blank lines, and strips newlines between tags. Returns minified output plus original and minified byte counts and savings percent.

Parameters

stringrequired

HTML source to minify.

Code examples

curl -X POST https://api.botoi.com/v1/minify/html \
  -H "Content-Type: application/json" \
  -d '{"code":"<!DOCTYPE html>\n<html>\n  <body>\n    <!-- banner -->\n    <h1>Hello</h1>\n  </body>\n</html>"}'

When to use this API

Minify server-rendered HTML at the edge

Pipe the output of your server framework through this endpoint before returning to the browser. Reduces first-byte payload without touching your render templates.

Pre-compress static HTML files

Build-step minification for Astro, Hugo, or 11ty output. The savings stack with Brotli, taking 10 KB HTML pages down to 2-3 KB on the wire.

Email template optimization

Transactional emails often have bloated HTML from WYSIWYG editors. Minify before sending to cut message size and improve deliverability (some providers penalize large bodies).

Frequently asked questions

Does it break <pre>, <script>, or <style>?
Whitespace inside these elements should be preserved for correctness, but this minifier performs global collapses that can alter whitespace in <pre> blocks. Test your output; for HTML with significant whitespace requirements, use a dedicated library.
Are conditional comments preserved?
No. All <!-- --> comments are stripped, including IE conditional comments. If you target legacy IE, exclude those blocks from minification.
What about HTML attribute whitespace?
Attribute values are preserved verbatim. Multi-space content in title="foo bar" stays intact.
How does this compare to html-minifier-terser?
This is a simpler, edge-friendly minifier focused on the safe wins (comments, whitespace). For advanced optimizations (attribute collapsing, implicit tag removal) use html-minifier-terser in your build.
What is the savings range?
Typical HTML savings are 20-45% depending on indentation and comment density. Templating frameworks that output heavily indented HTML see the biggest gains.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.