How to use a JavaScript minifier safely

JavaScript minification prints parsed code compactly, but module mode, modern syntax, comments, source maps, and regression testing all affect a safe release.

Open the JavaScript Minifier

What JavaScript minification does

A minifier removes formatting and ordinary comments, then prints a smaller program. Some tools also compress expressions or rename variables, which can increase savings but requires more careful configuration.

The ToolPixels minifier uses Terser with compression and name mangling disabled. It compacts syntax without running the submitted code.

How to use a JavaScript minifier

  1. Start from tested source and keep it in version control.
  2. Choose ES module mode for import, export, or top-level await.
  3. Paste JavaScript or open a UTF-8 file.
  4. Select Minify JavaScript.
  5. Test the compact output in the target runtime before deployment.

A basic minification example

Input

function add(a, b) {
  return a + b;
}

Output

function add(a,b){return a+b}

The function and parameter names remain because name mangling is disabled.

Script mode and module mode

ModeUse it for
ScriptClassic scripts without module-only syntax
ES moduleImports, exports, and top-level await

Selecting the wrong mode can cause valid source to fail parsing. JSX and TypeScript must be compiled before using this minifier.

Release checks

  • License and preservation comments should remain when required.
  • Source-map comments are removed and no replacement map is generated.
  • Minification does not bundle modules or transpile syntax.
  • Run automated tests against the exact compact artifact.
  • Serve JavaScript with Brotli or gzip for additional network savings.

Use the browser tool

Compact tested JavaScript locally without compression or name mangling, with an explicit ES module option.

Minify JavaScript