JavaScript Minifier API
Minify JavaScript with terser (mangle names, compress, drop comments) or pretty-print it. Syntax errors come back with line and column.
POST /api/v1/tools/javascript-minifierMCP javascript_minifierDeveloper ToolsMinify JavaScript with Terser to cut file size, with options to mangle names, compress code and keep licence comments. Beautify minified scripts to read them again.
Input
Send these as a JSON object. Unknown fields are rejected.
- input
- The JavaScript source (up to 100,000 characters). (string, up to 100000 characters, required)
- mode
- minify or format (pretty-print). (string, one of minify, format, default "minify")
- mangle
- Shorten local variable and function names when minifying. (boolean, default true)
- compress
- Apply compressions such as dead-code removal and constant folding when minifying. (boolean, default true)
- keepLicenseComments
- Keep /*! and @license comments when minifying; all other comments are removed. (boolean, default false)
- ecma
- Highest ECMAScript version the minified output may use: 5, 2015, 2016, 2017, 2018, 2019 or 2020. (integer, 5 to 2020, default 2020)
- module
- Parse as an ES module (allows import/export and top-level mangling). (boolean, default false)
- indent
- Spaces per indent level when formatting. (integer, 1 to 8, default 2)
curl https://pithlab.com/api/v1/tools/javascript-minifier \n -H "Authorization: Bearer $PITHLAB_KEY" \n -H "Content-Type: application/json" \n -d '{"input":"function add(first, second) {\n // Sum two numbers\n return first + second;\n}\nconsole.log(add(2, 3));"}'Example response
{
"ok": true,
"result": {
"output": "function add(first,second){return first+second}console.log(add(2,3));",
"stats": {
"before": 101,
"after": 69,
"savedPercent": 31.7
}
}
}