What is javascript minifier?
A minifier makes code smaller by removing things the browser does not need, such as comments, indentation and blank lines. Smaller scripts download faster and help page speed scores.
This tool uses a careful approach: it keeps strings intact, removes comments and trims whitespace, and it keeps line breaks so that code relying on automatic semicolons still works.
How to use the javascript minifier
- Paste your JavaScript.
- Check the size savings.
- Copy the result and test it before use.
How the javascript minifier works
The code is scanned character by character. Text inside quotes and template strings is copied as is. Line comments and block comments are dropped. Spaces and tabs are trimmed and spaces around common punctuation are removed.
Worked example
Common uses of the javascript minifier
- Shrinking a small script for a landing page.
- Cleaning code snippets before sharing.
- Learning how minification works.
- Quick fixes without a build tool.
- Reducing inline script size.
Tips and common mistakes
For large projects, use a build tool such as esbuild or Terser for variable renaming and dead code removal.
Always test minified code, especially if it contains regular expressions with slashes.
Background: what to know before you rely on it
Minification is part of front end performance. Every kilobyte of script must be downloaded, parsed and run, which matters most on slow phones and networks. Full minifiers shorten names and remove unreachable code, saving much more than whitespace removal. A safe whitespace and comment pass is still useful for small sites that do not have a build step. Combine it with server compression and caching for the best result, and keep original source files for editing.
Private, free and fast
This tool runs entirely in your browser. What you type or choose is not uploaded to a server and is not saved after you close the page, which keeps it fast and private. It is free to use as often as you like. See more in all developer tools, or browse the full list of tools.
Frequently asked questions
Is it safe?
It is conservative, but test your output. Unusual regular expressions can confuse any simple minifier.
Does it rename variables?
No. That needs a full parser.
Does it keep line breaks?
Yes, to protect code that relies on automatic semicolon insertion.
Is my code uploaded?
No.
Related tools
CSS Minifier
Paste your CSS and the minifier removes comments and extra whitespace to make the file smaller, with the...
Developer ToolsHTML Minifier
Paste your HTML and the minifier removes comments and extra whitespace between tags to reduce file size...
Developer ToolsJSON Minifier
Paste JSON to remove all extra spaces and line breaks. The tool validates the data first and shows how...
Developer ToolsSVG Optimizer
Paste your SVG code and the optimizer strips comments, metadata and editor leftovers and rounds long...
Developer ToolsJSON Formatter and Validator
Paste your JSON and the tool checks that it is valid, then formats it with indentation or compresses it...
Developer ToolsBase64 Encoder and Decoder
Base64 turns text or bytes into a safe string of letters and numbers. Choose encode or decode, paste...
Results are for information and education. For legal, financial, medical or security decisions, check with a qualified professional. Do not paste live secrets into any website.