JavaScript Minifier

Minify JS for production with Terser. This JavaScript minifier compresses and mangles your code, keeps license comments, can create a source map and reports syntax errors with the exact line and column.

Press Ctrl+Enter (⌘+Enter on Mac) to run now.

Original–
Minified–
Saved–
Gzipped–
script.min.js.map
Linecolumn

Minify JavaScript Online

JavaScript is usually the most expensive part of a page: it has to be downloaded, parsed and compiled before it runs. This JavaScript minifier makes that cost smaller by removing whitespace and comments, rewriting code into shorter equivalent forms and renaming local variables to one or two letters.

It runs Terser, the minifier that webpack uses by default in production mode, directly in your browser. You can keep license comments, choose the ECMAScript version the output may use, keep function and class names that your code relies on, and download a source map so the minified code can still be debugged. Syntax errors are shown with the exact line and column.

JavaScript code minified with shortened namesfunctionf(n){JavaScriptMinifier

How to minify JavaScript

  1. Paste your JavaScript or open a .js or .mjs file.
  2. Keep Compress and Mangle on for the smallest output. Tick “ES module” for code that uses import or export.
  3. Set the ECMAScript version your users’ browsers support and choose which comments to keep.
  4. Check the savings panel for the original size, the minified size, the percentage saved and the gzipped size.
  5. Copy or download script.min.js, plus script.min.js.map if you enabled the source map.

What Terser does to your code

  • Removes whitespace and comments. License comments (those starting with /*! or containing @license, @preserve or @copyright) are kept by default.
  • Compresses: evaluates constant expressions, drops unreachable code such as if (false) { … }, inlines single-use values, joins consecutive statements with commas and removes debugger statements.
  • Mangles: renames local variables and parameters, for example function calculateTotal(items, discount) becomes function calculateTotal(t,c). Property names are never renamed, so object keys and APIs keep working.
  • Leaves globals alone by default: top-level names may be used by other scripts on the page, so they are only renamed when you tick “Mangle top-level names” or “ES module”.

JavaScript minifier options

OptionWhat it doesWhen to change it
ECMAScript versionLets Terser use newer, shorter syntax up to that version (for example arrow functions from ES2015). It never converts newer syntax down to older versions.Pick ES5 only if the output must avoid any syntax that the input did not already use
CommentsKeep license comments, remove all, or keep allKeep license comments to respect open-source licenses
Compress passesRuns the compressor up to three times; later passes can find extra savingsTry 2 or 3 for large files
Mangle top-level namesAlso renames top-level functions and variablesOnly for self-contained scripts that nothing else calls
ES moduleParses as a module: strict mode and top-level names treated as privateCode with import / export
Keep function / class namesPreserves fn.name and Class.nameFrameworks, loggers or error reports that read names
Drop console callsRemoves console.* callsProduction builds without debug logging
Source mapCreates a map from minified positions to your original codeWhenever you need readable stack traces

Syntax errors and source maps

Terser parses the whole file before it minifies anything, so it doubles as a quick syntax checker. An error such as Unexpected token: punc (;) is shown with its line and column and a caret under the exact character. Common causes are a missing bracket, a stray comma or TypeScript type annotations, which must be compiled to JavaScript first. When “Source map” is ticked, the minified file ends with a //# sourceMappingURL=script.min.js.map comment; upload the map next to the script and browser dev tools will show your original code, with the original names, in stack traces and breakpoints. The map includes the original source, so do not publish it if the source must stay private.

Tips for smaller bundles

  • Test the minified file. Code that relies on Function.prototype.name, eval or with can behave differently after mangling; keep names or avoid those patterns.
  • Minify in your build with the same Terser options, so every release is minified the same way; use this page to compare settings.
  • Need to read minified code? The JavaScript Beautifier restores indentation and line breaks.
  • Optimize the whole page: minify markup and styles with the HTML Minifier and CSS Minifier, and compress images with the Image Compressor.

Frequently Asked Questions

Common questions about minifying JavaScript.

Paste the code into the left box. The minified version appears on the right with the bytes saved and a gzip estimate; copy it or download it as a .js file.

Terser 5, a widely used JavaScript minifier and the default minifier in webpack’s production mode. It runs in your browser.

Yes for normal code: Terser only applies transformations that keep the behaviour. Code that depends on function names, eval or exact toString() output may need “Keep function names” or should not be mangled.

No. The ECMAScript setting only controls which syntax Terser may use when it rewrites code. To run modern code in old browsers, transpile it with a tool such as Babel first, then minify.

Mangling renames local variables and function parameters to very short names. It saves a lot of bytes and does not change behaviour, because those names are not visible outside their scope.

Yes. With “Keep license comments”, comments starting with /*! or containing @license, @preserve or @copyright stay at the top of the output.

Tick “Source map”. The minified code then ends with a sourceMappingURL comment and a “Download .map” button appears; host both files in the same folder.

No. Terser is downloaded once from a CDN and runs in your browser, so your code never leaves your device.