Home/Tools/Minifiers/JavaScript Minifier

JavaScript Minifier

Minifiers

Minify and compress JavaScript code to reduce file size.

⚡ Instant🔒 Private, in your browser🆓 Free, no sign-up👥 For developers
Your data never leaves your browser. We do not store inputs.

What JavaScript Minifier does

The JavaScript Minifier shrinks JS files with Terser, the same minifier most build tools use: it strips comments and whitespace, shortens local variable names, and simplifies code without changing what it does. Paste a script, choose whether to shorten names or keep /*! license */ comments, and copy or download the smaller file, which is handy when you need a quick minified build without a bundler. Everything runs in your browser, so your code is never uploaded.

FV
Reviewed by the FreeToolsVerse team · Last updated · How we check our tools

Features and benefits

  • Uses Terser, the minifier behind most JavaScript build tools
  • Four options: compress (remove dead code), shorten local names, ES module mode and keep licence comments
  • Reports syntax errors with line and column instead of returning broken code
  • Your code is processed in your browser and never uploaded

How to use JavaScript Minifier

  1. Paste your JavaScript into the input box
  2. Choose whether to compress, shorten local variable names, treat the code as an ES module and keep licence comments
  3. Click Minify and check the before and after size
  4. Copy or download minified.js, and test the page that uses it

Who should use it

Made for developers. Typical uses:

  • Reducing JS file sizes for faster page loading
  • Minifying code before production deployment
  • Optimizing website performance and Core Web Vitals

Example

A 101-byte script that adds two numbers, with a comment and a console.log call, becomes 51 bytes: function add(d,n){return d+n}console.log(add(1,2)); With compress and renaming off it becomes 69 bytes, with the original names kept. A 141-byte snippet with an if (false) block shrinks to 72 bytes because the unused branch is removed.

Limitations and accuracy

It minifies one script at a time. It does not bundle files, resolve imports, create source maps or transpile for old browsers. Renaming can break code that reads function names or uses eval, in which case switch off "Shorten local variable names". Minified code is not a way to hide secrets.

Accuracy: Output is tested to keep behaviour unchanged. Keep your original files and test the minified version before you deploy it.

Expert Tip

Top-level names are only renamed in ES module mode, so global functions called from other scripts keep working by default. Test the minified build in a browser before you deploy it.

Frequently asked questions

How do I use the JavaScript Minifier?
Paste your script, choose the options and click Minify. You see the size before and after and can copy the result or download it as minified.js.
Which minifier does it use?
Terser, the same minifier most JavaScript build tools use. It supports modern ES2015+ syntax and runs in your browser.
What do the options do?
Compress removes dead code and simplifies expressions. Shorten names renames local variables. ES module mode also allows top-level names to be shortened. Keep licence comments preserves comments that start with /*! or contain @license or @preserve.
Will minifying change how my code works?
It should not, but renaming can break code that depends on function or parameter names. Test the result, and turn off renaming if it breaks anything.
Is my code uploaded anywhere?
No. Minification happens in your browser.

JavaScript Minifier: the complete guide

What the minifier does

The JavaScript Minifier shrinks scripts with Terser, the minifier used by most JavaScript build tools. It removes comments and whitespace, shortens the names of local variables, and simplifies the code without changing what it does. You paste a script, choose from four options, press Minify, and see the size before and after. The result can be copied or downloaded as minified.js. The code is processed in your browser and is never uploaded.

A worked example

This 101-byte script adds two numbers: a function called add with parameters first and second, a comment, and a console.log call. With the default settings, the result is 51 bytes: function add(d,n){return d+n}console.log(add(1,2)); The parameters have been renamed to single letters, the comment is gone and the spaces are removed, but the function name add is kept, because top-level names are not renamed unless the code is a module. With compression and renaming turned off, only whitespace and comments go, and the script is 69 bytes: function add(first,second){return first+second}console.log(add(1,2)).

The four options

Each checkbox changes how aggressive the minifier is.

  • Compress: removes dead code and simplifies expressions, running two passes. A block guarded by if (false) disappears, and several constants declared one after another can be merged into a single declaration. In one test, a 141-byte snippet became 72 bytes, and the unused branch was dropped.
  • Shorten local variable names: renames variables inside functions to short names. This gives a large saving, but it makes the code unreadable and can break code that depends on function parameter names.
  • ES module: treats the code as a module, which enables strict mode and allows top-level names to be shortened as well.
  • Keep licence comments: keeps comments that begin with /*! or contain @license or @preserve.

Syntax errors

Terser needs valid code. If the script has a syntax error, the tool reports the line and column, for example "JavaScript syntax error at line 1, column 10: Unexpected token". Fix the code first. For readable output instead of small output, use the JavaScript Formatter, which is the reverse operation for layout, although it cannot restore original variable names or comments.

Safe use

Test the minified script as you would any new build. Code that reads function names, uses eval or relies on Function.prototype.toString can behave differently after renaming, so turn off "Shorten local variable names" if it does. Minified code is not secure or private: names are shortened but the logic is still readable to anyone determined, so never put secrets in client-side scripts. The guide to minifying CSS, JavaScript and HTML covers how this fits into a build, and the JSON Minifier and CSS Minifier handle other file types.

Limits

The tool minifies one script at a time and does not bundle files, handle imports, create source maps or transpile newer syntax for older browsers. A bundler does those jobs in a real project. This tool is for quick jobs and for seeing how small a script can get.

Learning resources

Explore more in Minifiers, read the guides and articles, or see how we test our tools.

Share This Tool