JavaScript Minifier

Minify JavaScript online with Terser to shrink JS file size safely — free JS minifier.

About

About the JavaScript Minifier

Paste JavaScript and get it minified using Terser, a real parser-based minifier — the same one bundlers like webpack, rollup and vite run under the hood — so renaming variables and stripping dead code can't silently break your logic the way a naive regex-based minifier sometimes can.

Terser runs with both compression and name mangling on: it removes whitespace and comments, simplifies expressions and shortens local variable names. Top-level names are left alone by default, so global functions that other scripts call by name keep working, and comments marked /*! or @license are kept so licence notices survive.

Choose what to view about this tool

Guide

Using the JavaScript Minifier

  1. 1

    Step 1

    JavaScript is already selected below as the language.

  2. 2

    Step 2

    Paste your JS code into the input box.

  3. 3

    Step 3

    Click Minify to see the compressed output, entirely in your browser.

  4. 4

    Step 4

    Copy the minified code, and check the size reduction shown below the output.

  • Compresses and mangles JavaScript with Terser, including modern ES2015+ syntax
  • Keeps /*! … */ and @license comments so licence notices stay in place
  • Shows an error instead of producing broken output when the input has a syntax error
  • Shows the original size, the minified size and the percentage saved
  • Copy the result or download it as a file
  • Runs in your browser — free, no sign-up, and your code is never uploaded

Developers without a bundler

Developers shrink a small script before shipping it, without setting up a build.

Theme customisers

WordPress and Shopify users compress custom JavaScript before adding it to a theme.

Bookmarklet makers

Makers squeeze a script onto a single line for a bookmarklet.

Students

Students compare before and after to see what minification changes.

Minify another language

Examples

JavaScript Minifier examples

4 worked examples

01

A simple function

function add(a, b) { return a + b; } minifies down to function add(a,b){return a+b} with whitespace and unnecessary characters stripped.

02

Renaming local variables

A function with long local variable names gets those names shortened internally by Terser, while any exported names stay untouched so the code still works.

03

Checking the size reduction

Pasting a 20KB JavaScript file and minifying it might shrink it to 8KB, with the exact percentage saved shown below the output.

04

Parameters renamed, names kept

function add(first, second) { var total = first + second; return total; } becomes function add(d,e){return d+e} — the local names shrink and the temporary variable disappears, but the function name stays.

FAQ

Frequently asked questions

Quick answers to common questions about the JavaScript Minifier.

How do I minify JavaScript?

Paste your JS code above, make sure JavaScript is selected, then click Minify. The minified output appears in the box below it — everything runs in your browser, using Terser.

Is this JavaScript minifier free?

Yes. It's free, with no sign-up and no limit on how much code you minify.

Will minifying break my JavaScript?

It shouldn't, since Terser actually parses the code into an AST rather than blindly stripping characters — the same minifier is trusted in production by webpack, rollup and vite. Always test minified output before shipping it, as with any build step.

Does it support modern JavaScript syntax, like arrow functions and classes?

Yes — Terser understands modern ES module and class syntax, not just older JavaScript.

Is my code uploaded anywhere?

No. Minification runs entirely in your browser after Terser loads from this site — your code never leaves your device.

Can I minify CSS or HTML here too?

Yes — switch the language dropdown, or use the dedicated CSS minifier or HTML minifier page.

Are top-level function and variable names renamed?

No. Terser shortens local variables and function parameters, but names at the top level of your script — like a global function other scripts call — are left alone, so nothing that depends on them breaks.

Can I download the minified file?

Yes. Use the Download button to save the result, or Copy to put it on your clipboard. A panel underneath shows the original size, the minified size and the percentage saved.

Does it create a source map?

No, it produces the minified code only. If you need source maps to debug minified code in production, run Terser as part of your build tool instead.

What happens if my code has a syntax error?

Minifying stops and a message asks you to check the code is valid JavaScript, so no broken output is produced. Fix the error and click Minify again.

Still have a question? Contact us

Report a problem

JavaScript Minifier

What went wrong?
    or paste a screenshot