JavaScript Minifier
Compress JavaScript for production using the same engine modern build tools rely on. Code is parsed properly, so a syntax error is reported with its line instead of producing broken output.
- Runs in your browser
- No sign-up
- Free to use
How to use JavaScript Minifier
- Paste your JavaScript or open a .js file.
- Choose whether to shorten variable names (mangle) and apply code optimisations (compress).
- Select Minify JavaScript.
- Check the size saving, then copy or download the minified code.
JavaScript Minifier features
Powered by Terser
The minifier used by webpack, Rollup and Vite, running in your browser.
Name mangling
Local variables and function parameters are renamed to single letters.
Compression passes
Dead code is removed, constants folded and expressions simplified.
Modern syntax
Understands ES2020+ features including modules, classes, async functions and optional chaining.
Real syntax checking
Invalid code is rejected with the line and column of the error.
Private
Source code is not uploaded.
When to use JavaScript Minifier
- Minifying a small script for a site that has no build pipeline.
- Shrinking a bookmarklet or embeddable snippet.
- Checking how much a library could be reduced.
- Quickly validating that a file parses as JavaScript.
JavaScript Minifier FAQ
What is the difference between compress and mangle?
Compress rewrites code into shorter equivalent forms and removes code that can never run. Mangle renames local variables and parameters to short names. Used together they give the smallest output.
Will minification break my code?
Correct code keeps working. Problems occur only when code depends on function or variable names as strings, for example reading Function.name, or relies on global names that are not actually global. Top-level names are not renamed.
Does it support ES modules?
Yes. Tick the Module option when the code uses import or export so that top-level scope is treated correctly.
Are comments removed?
Yes, except licence comments starting with /*! or containing @license or @preserve, which are kept by default.
Can I minify TypeScript or JSX?
No. Compile to plain JavaScript first. Type annotations and JSX are not valid JavaScript and produce a syntax error.
Can minified code be debugged?
Yes, with a source map: a file that maps positions in the minified code back to the original source, so browser developer tools show readable code and correct line numbers. Without a source map, use the JavaScript Formatter to make minified code readable, although the short variable names remain.
Should I keep the original file?
Always. Minified code is not meant to be edited: names are shortened and the layout is gone. Keep the readable source under version control and treat the minified file as a build product that can be regenerated at any time. For debugging in production, a source map connects the minified code back to the original lines.
How JavaScript minifiers work
Unlike a regex-based whitespace stripper, a real minifier parses the program into a syntax tree. That gives it an exact understanding of scopes, so it knows which names are local and can be renamed safely, and which expressions have no side effects and can be removed or reordered.
After transforming the tree it prints the code again using the fewest characters possible: no optional semicolons, shortest number forms, quotes chosen to avoid escapes. On typical application code this removes 40–70% of the file size before gzip. Keep your original source and treat the minified output as a build artefact, since it is not meant to be edited.
Source maps bridge the gap between minified code and readable source. A source map is a separate file that records how each position in the minified output corresponds to a line and column in the original files, so browser developer tools can show readable code and meaningful stack traces while users download the small version. Upload source maps to your error-tracking service, or serve them only to your own team, if you prefer not to publish the original source alongside the site.
The usual place for minification is a build step that runs before deployment, but a quick manual pass is useful for single files, snippets embedded in a page, or checking how much a script could shrink. After minifying, load the page and try its main functions once: the code is logically identical, yet a test is the only proof that nothing depended on a name or a formatting detail.