JavaScript minifier

Paste your code and get a smaller version with comments and extra whitespace removed, plus the bytes and percentage saved. It is a basic and safe minifier: it does not rename variables. Free, in your browser.

How to use it

  1. Paste your code in the Your JavaScript box.
  2. The Minified JavaScript appears below with the original size, new size and percentage saved.
  3. Click Copy or Download and test the result before publishing.

Complete guide to minifying JavaScript

What this minifier does

JavaScript is usually the heaviest part of a page after images, and the browser must download and parse it before the code can run. Minification removes everything that does not change how the code behaves: comments, indentation, blank lines and unneeded spaces. The result is a smaller file that does exactly the same thing. This tool is a basic and safe minifier: it works on the text of your code and never renames variables, removes unused functions or rewrites expressions. For those advanced optimizations, use a build tool such as esbuild, Terser or Vite.

How it stays safe

JavaScript is harder to minify than CSS, because whitespace can change the meaning of code. The tool therefore reads the code in a careful way:

  • Strings and template literals are untouched. Spaces inside "a b" or inside a backtick string, including the ${ } parts, are kept.
  • Regular expressions are recognized. A / that starts a regex, as in /a b/g, is not mistaken for a division or a comment.
  • Line breaks are kept where they matter. JavaScript can end a statement at a line break when a semicolon is missing, and return followed by a line break returns nothing. The tool keeps those line breaks instead of joining lines into code that behaves differently.
  • Comments starting with /*! are kept, because they usually carry licenses.

If a string, template or comment is opened and never closed, you get a clear error instead of broken output. Everything runs in your browser and your code is never uploaded.

Worked example

Paste this into Your JavaScript:

// Greeting
function greet(name) {
  /* msg */
  var msg = "Hello, " + name + "!";
  return msg;
}
console.log(greet("World"));

The Minified JavaScript is:

function greet(name){var msg="Hello, "+name+"!";return msg;}
console.log(greet("World"));

The Size panel reports 128 bytes before, 89 bytes after, 39 bytes saved, a 30.5% reduction. The comments, the indentation and the spaces around operators are gone. The line break before console.log stays because the line before it ends with a closing brace and not a semicolon, which is the safe choice. The semicolon before the closing brace is also kept.

Tips and common mistakes

  • Always test the minified file before publishing, ideally with the same checks you use for the original. No minifier replaces a quick run of your page.
  • If you write code without semicolons, the tool preserves the line breaks that your style depends on, so the savings are smaller than for code that always ends statements with a semicolon.
  • A minified file is hard to debug. Keep the original as your source, and serve the minified copy only in production.
  • Do not minify a file twice or paste already minified code from a library and expect large savings; there is little left to remove.
  • Renaming variables (mangling) can cut the size much further, but it needs a real parser. If size matters a lot, add Terser or esbuild to your build and use this tool for quick manual jobs.

Related tools

Shrink the rest of the page with the CSS minifier and the HTML minifier. To check a pattern before putting it in your code, use the regex tester, and to encode data for a script, the Base64 encoder.

Questions

Does it rename variables or remove dead code?

No. It only removes comments and whitespace that are not needed. For maximum compression, tree shaking or renaming, use a bundler such as esbuild, Terser or Vite in your build.

Is it safe for my code?

It respects strings, template literals and regular expressions, and keeps line breaks where removing them could change the meaning, such as after return or between statements without semicolons. Still, always test the minified file.

Is my code sent anywhere?

No. The minification runs in your browser and nothing is uploaded or stored.

What happens with /*! comments?

Comments that start with /*! are kept, since they usually hold licenses that must stay in the file.