JS / CSS / HTML Minifier API

Minify JavaScript (Terser), CSS (CSSO), HTML and JSON, with the byte and gzip size before and after; the language is detected automatically.

POSThttps://apibox.io.vn/v1/minify
Developer utilities▶ Try it online

The minifier shrinks front-end code for production. JavaScript goes through Terser (two compression passes, local names mangled, module=true for ES modules), CSS through CSSO (merges rules, shortens colours and values, restructure=false for a safer pass), JSON is re-serialised without whitespace, and HTML loses comments and whitespace between block tags while its inline <script> and <style> blocks are minified too.

Leave type empty to detect the language from the code, or set js, css, html or json. License comments (/*! … */, @license, @preserve) are kept. In HTML, <pre> and <textarea> content is left untouched, one space is kept between inline tags, and minify_js=false / minify_css=false leave embedded code as it is.

The answer gives the minified code and size: input and output bytes, the percentage saved and gzip sizes, the number that matters for download time. Syntax errors return parse_error with the line and column.

Parameters

NameInTypeRequiredDefault
codebodystringyesThe code to minify (max 2,000,000 characters).
typebody|querystringnojs, css, html or json (default: detected).
manglebody|querybooleannotrueJS: shorten local names.
modulebody|querybooleannofalseJS: treat the code as an ES module.
restructurebody|querybooleannotrueCSS: merge and move rules.
minify_jsbody|querybooleannotrueHTML: minify inline scripts.
minify_cssbody|querybooleannotrueHTML: minify <style> and style="".

Example

curl -X POST "https://apibox.io.vn/v1/minify" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code":"function tinhTong(soThuNhat, soThuHai) {\n  // cộng hai số\n  const tong = soThuNhat + soThuHai;\n  return tong;\n}\nconsole.log(tinhTong(1, 2));"}'

Response

{
  "type": "js",
  "minified": "function tinhTong(n,o){return n+o}console.log(tinhTong(1,2));",
  "size": {
    "input": 144,
    "output": 61,
    "saved_percent": 57.6,
    "gzip_input": 132,
    "gzip_output": 74
  }
}

Use cases

  • Minify assets in a build step without installing tools
  • Shrink HTML e-mail templates and landing pages
  • Compact JSON before storing or sending it
  • Measure how much a file gains from minification and gzip

FAQ

Is my code changed in behaviour?

Terser and CSSO apply safe transformations. If a script relies on function names, send mangle=false.

Does it support TypeScript or SCSS?

No: compile to JavaScript or CSS first, then minify.

What is the size limit?

2,000,000 characters of code per call.

Related APIs

Start with 1,000 free requests every month. Get free API key →