What is the JavaScript Minifier?
JavaScript is usually the heaviest part of a web page, and every kilobyte has to be downloaded, parsed and executed. Minification shrinks scripts by removing comments, whitespace and line breaks, and in more advanced tools by renaming local variables to short names and simplifying expressions.
A simple minifier like this one focuses on safe, whitespace and comment removal. That is predictable and will not break your code, but it saves less than a full optimizer such as Terser or esbuild, which also shorten identifiers. For production, use a build tool with source maps; use this page for snippets, bookmarklets and quick checks.
When to use the JavaScript Minifier
It suits small scripts that do not go through a bundler: analytics snippets, bookmarklets saved in the browser, inline scripts for static pages, and code you paste into a CMS field with a length limit. Smaller scripts download and parse faster, which improves interactivity on slow connections. The beautify mode helps when you need to read a vendor script or investigate a production error that points to line 1, column 48210 of a minified bundle.
How to use the JavaScript Minifier
- Paste your JavaScript into the input area.
- Choose Minify or Beautify.
- Review the output and the reported size reduction.
- Copy the result into your page, bookmarklet or build output.
- Run your code once in the browser console to confirm it still works.
Examples
Source:
// Add two numbers
function add(a, b) {
const sum = a + b;
return sum;
}
console.log(add(2, 3));Minified (whitespace and comments removed):
function add(a,b){const sum=a+b;return sum}console.log(add(2,3));Common errors and tips
- Missing semicolons relying on automatic semicolon insertion can break when lines are joined; terminate statements explicitly.
- A
//comment at the end of a line must be removed before joining lines, or it would comment out the following code. - Regular expressions and template literals contain whitespace that is significant and must not be altered.
- Never rely on function names (
fn.name) in code that will be renamed by an advanced minifier. - Always keep the unminified source and a source map for debugging production errors.
Privacy: runs entirely in your browser
Your source code is processed entirely in the browser; proprietary scripts are never uploaded or stored. This tool runs entirely in your browser: nothing you enter is uploaded, stored or logged on our servers, and it keeps working even if you go offline after the page has loaded.
Frequently asked questions
Does minification change what my code does?
It should not. Safe minification removes only comments and whitespace. Always test the output, especially if your code relies on automatic semicolon insertion.
What is the difference between minifying and obfuscating?
Minifying reduces size. Obfuscation deliberately makes code hard to understand. Neither is a substitute for keeping secrets on the server.
Why is my minified file only slightly smaller?
Whitespace removal alone saves modest amounts. Tools that rename variables and eliminate dead code, such as Terser, achieve much larger reductions.
Can I read minified code again?
Beautify restores indentation and line breaks, but original variable names and comments are not recoverable unless you have a source map.
Ratings & reviews
–
0 reviews
- 5 star
- 0 reviews (0%)
- 4 star
- 0 reviews (0%)
- 3 star
- 0 reviews (0%)
- 2 star
- 0 reviews (0%)
- 1 star
- 0 reviews (0%)
No reviews yet — be the first to share your experience.
Write a review
Reviews are moderated before they appear.
Related tools
Beautify, minify and validate JSON instantly, with exact line and column for every syntax error.
Use toolEncode text to Base64 or decode Base64 back to readable UTF-8, including URL-safe Base64.
Use toolGenerate random v4 and time-ordered v7 UUIDs in bulk, with one-click copy and format options.
Use toolTest JavaScript regular expressions live, with highlighted matches, capture groups and flag toggles.
Use toolDecode JSON Web Tokens to inspect the header, payload and expiry, all without sending the token anywhere.
Use toolConvert Unix timestamps to readable dates and back, in UTC or your local timezone, in seconds or milliseconds.
Use tool
