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.
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
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
code | body | string | yes | The code to minify (max 2,000,000 characters). | |
type | body|query | string | no | js, css, html or json (default: detected). | |
mangle | body|query | boolean | no | true | JS: shorten local names. |
module | body|query | boolean | no | false | JS: treat the code as an ES module. |
restructure | body|query | boolean | no | true | CSS: merge and move rules. |
minify_js | body|query | boolean | no | true | HTML: minify inline scripts. |
minify_css | body|query | boolean | no | true | HTML: 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));"}'const res = await fetch('https://apibox.io.vn/v1/minify', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"code": "function tinhTong(soThuNhat, soThuHai) {\n // cộng hai số\n const tong = soThuNhat + soThuHai;\n return tong;\n}\nconsole.log(tinhTong(1, 2));"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/minify",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"code": "function tinhTong(soThuNhat, soThuHai) {\n // cộng hai số\n const tong = soThuNhat + soThuHai;\n return tong;\n}\nconsole.log(tinhTong(1, 2));"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/minify');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"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 = curl_exec($ch);
print_r(json_decode($response, true));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
UUID Generator
Generate up to 1,000 UUID v4, time-ordered UUID v7, ULID, Nano ID or random hex IDs per request. Secure randomness, optional uppercase.
⏱Cron Expression Parser
Validate a cron expression and get its next run times in any timezone, with a plain-English description. Supports 5, 6 and 7-field cron syntax.
🕒Time & Timezone Converter
Get the current time in any timezone, convert between timezones and Unix timestamps (seconds or ms), with UTC offset and weekday for up to 30 zones.