Skip to content
PithLab

↑↓ to move · Enter to open · Esc to close

JavaScript Minifier and Beautifier

Shrink JavaScript with Terser or format it for reading.

Use via API

Minify JavaScript with terser (mangle names, compress, drop comments) or pretty-print it. Syntax errors come back with line and column. Send JSON, get JSON back.

POST https://pithlab.com/api/v1/tools/javascript-minifier

curl https://pithlab.com/api/v1/tools/javascript-minifier \
  -H "Authorization: Bearer $PITHLAB_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input":"function add(first, second) {\n  // Sum two numbers\n  return first + second;\n}\nconsole.log(add(2, 3));"}'

Fields and responseOpenAPI documentGet an API key

About the JavaScript Minifier

Minify 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.

How to use the JavaScript Minifier

  1. Paste your JavaScript.
  2. Choose whether to mangle names and compress code, and pick the ECMAScript version of your output.
  3. Press Minify. Syntax errors are reported with their line and column.
  4. Press Beautify to turn minified code back into readable, indented code.
  5. Copy the result or download it as a .js file.

Examples

Minify a function with mangling and compression

Input

function add(first, second) {
  // Add two numbers
  const total = first + second;
  return total;
}
console.log(add(2, 3));

Output

function add(d,n){return d+n}console.log(add(2,3));
Minify and keep a licence comment

Input

/*! MIT licence */
const greeting = 'Hello';
console.log(greeting + ', world');

Output

/*! MIT licence */
const greeting="Hello";console.log("Hello, world");
Beautify minified code

Input

function f(a){if(a){return 1}else{return [1,2,3].map(x=>x*2)}}

Output

function f(a) {
  if (a) {
    return 1
  } else {
    return [1, 2, 3].map(x => x * 2)
  }
}

Frequently asked questions

What do mangle and compress do?

Mangle renames local variables and parameters to short names. Compress rewrites code into shorter equivalent forms, for example by folding constants and removing unreachable code.

Does the ECMAScript target convert modern syntax?

No. The target only stops Terser from introducing newer syntax while compressing. It does not turn arrow functions or classes into ES5; use a transpiler such as Babel for that.

Why are top-level names not shortened?

Top-level names in a classic script are global and other scripts may use them, so they are kept. Tick ES module to treat the code as a module, where top-level names can be mangled safely.

Can minified code be reversed?

Beautify restores indentation and line breaks, but removed comments and original variable names cannot be recovered. Keep your source files and use source maps in your build.

Is my code uploaded?

No. Terser and js-beautify run inside your browser, so your code never leaves your device.