N
NJHTools

JavaScript Minifier

Paste JavaScript and get a smaller file as you type, with the bytes saved and a gzip estimate. Switch to Beautify to turn minified code back into readable code.

Paste code, or drop a .js / .mjs / .cjs file here. 635 B

Result

635 B → 444 B30.1% smallergzip ≈ 311 B

Runs entirely in your browser. Your code is never uploaded; only your options are remembered on this device.

Minifying stylesheets? Use the CSS Minifier.

How to minify JavaScript online

  1. Paste or open your code. Paste JavaScript into the left box, or open or drop a .js, .mjs or .cjs file (up to 10 MB). A sample is loaded so you can see a result first.
  2. Choose the minify options. Shorten variable names and compress for the smallest file. Turn on ES module for code with import or export, Keep function and class names if your code relies on those names, and leave Keep license comments on to preserve /*! … */, @license and @preserve notices.
  3. Check the result. The minified code appears on the right as you type, with the size before and after, the percentage saved and an estimated gzip size. A syntax error shows its line and column, with a button to jump to it.
  4. Copy or download. Copy the result or download it as a .min.js file, plus the .map file if you created a source map (the minified code then ends with a sourceMappingURL comment that points to it). Test the minified script before you ship it.
  5. Beautify minified code. Switch to the Beautify tab to make a minified file readable again, with a 2-space, 4-space or tab indent and optional line wrapping.

Features

  • Minify JavaScript with Terser: remove whitespace and comments, shorten local names and compress code
  • ES module support for import / export, plus an option to keep function and class names
  • Keep /*! license comments, and download a source map (.map) for debugging
  • Beautify (unminify) JavaScript with a 2-space, 4-space or tab indent and optional line wrapping
  • Size before and after, percent saved and an estimated gzip size
  • Syntax errors with line and column, and a button to jump to the problem
  • Open or drop .js, .mjs and .cjs files; copy or download as .min.js
  • Options are remembered in your browser; files up to 10 MB, with a Run button for large ones
  • Free, no signup; your code is processed on your device and never uploaded

Minification by Terser (BSD-2-Clause licence) and formatting by js-beautify (MIT licence), both running in your browser. Minifying makes code smaller, not secret: always test the minified file before you deploy it.

Frequently Asked Questions

What does a JavaScript minifier do?↓

It rewrites your script into smaller code that behaves the same. It removes whitespace, line breaks and comments, shortens local variable and parameter names, and with Compress drops unreachable code, joins declarations and simplifies expressions. The browser downloads and parses fewer bytes, so pages load faster. This tool uses Terser, the minifier behind many popular JavaScript build tools.

How much smaller will my JavaScript get?↓

It depends on the code. Readable, well-commented source often shrinks by roughly 30 to 60 percent, while code that is already minified barely changes. The tool shows the exact size before and after and an estimated gzip size, which is closer to what visitors actually download when your server compresses files.

Is minification safe? Will it break my code?↓

Terser is designed to keep valid code working, but some code depends on things minification changes: function.name or class names (turn on Keep function and class names), names looked up as strings, or variables shared with other scripts in unexpected ways. Invalid JavaScript stops with a syntax error instead of producing output. Always test the minified file before deploying it, and keep your original source, because minification cannot be fully undone.

What is the difference between mangle and compress?↓

Mangle renames local variables, function parameters and inner functions to short names such as a, b and c; it does not rename object properties or, in a normal script, global names. Compress rewrites the code itself: it removes dead code and unused variables, folds constant expressions, joins statements and turns if/else into shorter forms. Both together give the smallest result; turn one off if you are tracking down a problem.

Does it support ES modules and modern JavaScript?↓

Yes. Terser understands modern syntax such as arrow functions, classes, async/await, optional chaining and template literals. Turn on ES module when the file uses import or export: the code is then treated as a module, which is always in strict mode and lets top-level names be shortened too. TypeScript and JSX must be compiled to JavaScript first.

What is a source map, and do I need one?↓

A source map (.map file) links each position in the minified file back to your original code, so browser developer tools can show readable code and the right line numbers in errors. Turn on Create a source map: a //# sourceMappingURL comment pointing to the .map file is added to the end of the minified code, so download the .map file and upload it next to the .min.js file. It is optional; anyone who can load the map can read your original source, so many sites keep it private.

Should I minify or gzip my JavaScript?↓

Both: they work together. Minifying removes characters the browser does not need, and gzip or Brotli compression on the server then shrinks what is left for transfer. Minified files still compress well, so the combination is usually much smaller than either alone. The gzip figure shown here is an estimate; your server's settings decide the real number.

Can I unminify JavaScript? Is minifying the same as obfuscating?↓

The Beautify tab re-indents minified code so you can read its structure, but comments and original variable names are gone for good. That is also why minifying is not obfuscation or security: anyone can beautify your script and follow the logic, so never put passwords, API secrets or other private data in client-side code. Your code stays in your browser and is never uploaded; the anonymous usage statistics record only the action and a rough size range, never the code.

All Text & Dev Tools →

Last updated: