← All tools

JavaScript Minifier

Minify JavaScript in your browser: comments and whitespace removed, code compressed and names shortened (terser).

Free tool No account
Input
Output
AI uses your own key (several are free); a button opens a short setup.
Ready72 in · 0 outProcessed locally · No upload
Enjoying JavaScript Minifier?Your review and ideas shape what we build next.

Review JavaScript Minifier

Please don't include file contents or passwords.

About the JavaScript Minifier

Make JavaScript smaller with Terser, the minifier many build tools use: comments and whitespace are removed, code is compressed, and local variable names can be shortened. Or beautify minified JavaScript so you can read it. Syntax errors are shown with their line and column.

How to use it

  1. Paste your JavaScript into the Input box.
  2. Choose Minify (tick or untick shorten names and keep licence comments) or Beautify. Tick ES module if the code uses import or export.
  3. The result appears on the right, with the size before and after in the status line.
  4. Copy or download it.

Tip: If minifying gives an error about import or export, tick ES module: modules are read with slightly different rules.

What the minifier does

Removes comments and whitespace
Everything only people need: comments, line breaks and indentation.
Compresses code
Simplifies expressions, drops unreachable code and joins statements, without changing what the code does.
Shortens names (optional)
Local variables and function parameters such as total and userName become one or two letters. Global names and object property names are never changed, so other scripts can still use them.
Keeps licence comments (optional)
Comments starting with /*! or containing @license or @preserve stay.

Beautify: reading minified code

Beautify lays minified JavaScript out with line breaks and indentation and keeps comments, without compressing or renaming anything. It's the quickest way to read a third-party script, follow an error in a minified bundle, or study how something works.

Names that were shortened when the file was minified can't be recovered; a source map from the original project is the only way back to them.

Modern JavaScript

Terser understands modern syntax: arrow functions, classes, let and const, template strings, async and await, optional chaining (?.), and import and export when ES module is ticked. It doesn't read TypeScript or JSX; compile those to plain JavaScript first.

When to use this tool, and when a build tool

For a quick snippet, a bookmarklet, a script for a CMS, or an inline script in an HTML page, this tool is the fastest way. For a full app, a build tool (Vite, esbuild, webpack) minifies every file automatically and writes source maps so errors in production point back to your real code.

Before and after

function add(total, extra) { // sum two numbers return total + extra; } becomes function add(n,d){return n+d}: the comment, the spaces and the line breaks are gone, and the two parameters have one-letter names. The function's own name, add, stays, because other code may call it.

With shorten names unticked you get function add(total,extra){return total+extra}, a little longer but still much smaller than the original.

Minify vs obfuscate

Minifying makes code smaller, not secret. Anyone can beautify it and read the logic again. Don't put passwords, API secrets or private keys in JavaScript that runs in the browser; keep them on your server.

What gets compressed

Constant expressions
1000 * 60 becomes 60000.
Unreachable code
if (false) { … } and code after a return are dropped.
Shorter forms
true and false can become !0 and !1, and if/else can become a ? b : c.

Tips and tricks

Make a bookmarklet

Minify your script, then put javascript: in front of it to save it as a bookmark.

Debug a minified error

Beautify the file and use the line and column from the browser's error to find the code.

Keep names for debugging

Untick shorten names; the code is still much smaller and error messages stay readable.

Check the saving

The status line shows the size before and after; minified code also compresses better with gzip.

Keep licences

Tick keep licence comments when a library's licence asks you to keep its notice.

Keep secrets local

Code is minified in your browser and never uploaded.

Questions

Does minifying change what my code does?

No. Terser only makes changes that keep the same behaviour. Test the result anyway, as with any build step.

What does shorten names do?

It renames local variables and parameters to short names (a, b, c). Global names and object properties stay the same, so other code can still call them.

Can I minify code with import and export?

Yes. Tick ES module and the code is read as a module.

Can I un-minify JavaScript?

Yes. Choose Beautify to get readable layout back. Names that were shortened can't be restored.

Why do I get a syntax error?

The code isn't valid JavaScript: often a missing bracket, TypeScript types or JSX. The error gives the line and column.

How much smaller does JavaScript get?

Usually 30–60%, depending on how many comments and long names the code has.

Does it support TypeScript?

No. Compile TypeScript to JavaScript first, then minify the result.

Is Terser safe to use on my code?

Terser is the minifier used by webpack, Vite and many other build tools, so it is well tested. Still, run your tests or open the page after minifying, especially when code relies on function names, such as some dependency injection setups.

What does the ES module option do?

Tick it when your code uses import or export. Terser then parses the file as a module, which also lets it shorten top-level names because they aren't global.

Can I unminify JavaScript?

Beautify puts the code back on separate lines with indentation so it is readable again. Original variable names and comments can't be recovered; that needs a source map from whoever built the file.

Is my code uploaded?

No. The tool runs in your browser; what you paste never leaves your device and nothing is stored on a server.

Related tools

Updated