JavaScript Minifier — Free Online Tool

JavaScript Minifier

Paste JavaScript and get a minified version with Terser, the minifier used by most JavaScript build tools. Minification runs in your browser; your code is never uploaded.

What minification does

Terser parses your code and rewrites it to be as small as possible while behaving the same:

  • Removes whitespace, line breaks and comments.
  • Shortens local variable and parameter names (function f(firstName) → function f(o)).
  • Simplifies code — removes unreachable code, folds constant expressions, and shortens if/return patterns.
  • Keeps top-level names unchanged, so functions and variables used by other scripts still work.
  • Never touches the contents of strings.

Example

// greet a user
const msg = "Hello , world"; // keep spaces
function f(x, y) { return x - -y; }
console.log(msg, f(1, 2));

becomes

const msg="Hello , world";function f(o,l){return o- -l}console.log(msg,f(1,2));

The comments are gone and the parameters are renamed, but the string is untouched and o- -l keeps its space — writing o--l would change the meaning.

Errors

Minification needs valid JavaScript. If the code cannot be parsed, the tool shows Terser's error with the line and column, for example Name expected (line 1, column 4).

Other buttons

  • Format pretty-prints JavaScript with Prettier — useful for reading minified code.
  • Validate checks the syntax without changing anything.

Tips

  • Use a build tool for production. Bundlers such as Vite, webpack and esbuild minify automatically and also produce source maps. This tool is for one-off snippets, bookmarklets and inline scripts.
  • Modern syntax is supported — ES modules, classes, arrow functions, optional chaining and async/await.
  • TypeScript and JSX must be compiled first; Terser only understands plain JavaScript.