What this tool does
JavaScript Minifier
Your input is sent to the server for this request and is not saved as a tool content record. Infrastructure logs may still record request metadata, so do not submit secrets.
JavaScript Minifier removes selected comments, debugger statements, whitespace, and console calls with a lightweight text-based processor. It does not execute the submitted code.
This is not an AST-based compiler, bundler, transpiler, source-map generator, or tree shaker. Strings, regular expressions, template literals, and aggressive cleanup require testing in the target application.
How to use this tool
How to minify JavaScript
Paste JavaScript or upload a file up to 1 MB.
Choose comment, whitespace, debugger, console, and aggressive cleanup options.
Select Minify JavaScript and inspect the compact output.
Run the result in your target browsers before replacing a production asset.
Before and after example
JavaScript minification example
Input
function run() {
const ready = true;
console.log('ready');
return ready;
}
Output
function run(){const ready=true;console.log('ready');return ready;}
Options, errors, and limitations
JavaScript options, syntax, and testing
Parent category
Explore the Minify Tools hub
Pages focused on CSS, HTML, JavaScript, and JSON minification workflows.
Related articles
Read more from the developer blog
Practical guides
Troubleshoot and choose the next step
FAQ
JavaScript Minifier FAQ
What is the difference between JavaScript minification and obfuscation?
Minification primarily reduces file size by shortening formatting and sometimes identifiers, while obfuscation intentionally makes code harder to understand. Neither technique should be treated as a security boundary because browser delivered JavaScript can still be inspected and analyzed.
Can JavaScript minification break working code?
Yes, especially when code relies on function names, variable names, eval, dynamic property access, framework annotations, or invalid syntax. Modern build tools reduce these risks, but production testing is still essential after minification.
What are JavaScript source maps and should I keep them?
Source maps connect minified production code back to the original source so developers can debug errors. You can generate them for internal debugging, but decide carefully whether to publish them publicly because they may expose readable source code.
Will a JavaScript minifier remove comments?
Most minifiers remove normal comments, although license banners and specially marked comments can sometimes be preserved. Confirm your licensing obligations before stripping comments from third party libraries.
Should console.log and debugger statements be removed?
They are often removed from production builds to reduce noise and avoid exposing debugging information, but doing so is a separate transformation from basic whitespace minification. Make sure you do not remove logs that your production monitoring or support workflow actually needs.
Can a minifier handle modern JavaScript syntax?
That depends on the parser and version used by the tool. Code using newer ECMAScript features should be processed by a minifier that explicitly supports that syntax, or transpiled first when older browser compatibility is required.
Do I still need JavaScript minification with Brotli or Gzip?
Yes, they can work together. Minification removes unnecessary source characters and may shorten identifiers, while Brotli or Gzip compresses the resulting bytes during delivery.
What is variable mangling in JavaScript minification?
Mangling renames local variables and sometimes other identifiers to shorter names. It can reduce size significantly, but aggressive property mangling can break code when names are referenced dynamically or shared across boundaries the minifier cannot see.
Why can eval or dynamic code cause minification problems?
Code that constructs or accesses names dynamically can depend on the original identifier text. Because a minifier may rename those identifiers, the dynamic reference can stop matching unless the tool detects and protects that usage.
Should I keep the original JavaScript source files?
Yes. The readable source should remain the canonical version in your project, while minified files are generated for deployment. This preserves maintainability, debugging, code review, and future builds.