When to use the JavaScript Minifier
Small websites without a build step
Minify a script before uploading it to a simple HTML site.
Bookmarklets and snippets
Shrink a snippet so it fits in a bookmark, tag manager or widget field.
Embedding scripts
Reduce inline scripts in landing pages and email-capture forms.
Quick comparison
See how much of a file is comments and whitespace before deciding on a full build tool.
Features and benefits
- Removes // and /* */ comments (keeps /*! license comments)
- Understands strings, template literals and regex literals
- Keeps line breaks where automatic semicolon insertion needs them
- No variable renaming – predictable, readable output
Example
// add two numbers
function add(a, b) {
return a + b;
}function add(a,b){return a+b;}How the JavaScript Minifier works
The minifier tokenises your code so it knows the difference between code, strings, template literals, regular expressions and comments. It removes comments and unnecessary spaces but keeps a line break wherever JavaScript’s automatic semicolon insertion might depend on it – for example after a return or between statements without semicolons. Variable names are not changed, so error messages and stack traces stay readable.
A real-life example
A teacher has written a small quiz script for a school website with plenty of comments explaining each step to students. The file is 14 KB. Minified, it is 6 KB, which loads quickly on the school’s slow shared hosting. She keeps the commented version on the class page for students to study and uploads the minified version to the live site.
Good to know
Comments and indentation make code readable for people but add bytes that every visitor downloads. Removing them is the safest form of minification.
JavaScript has automatic semicolon insertion: in some places a line break acts like a semicolon. This minifier keeps a line break wherever removing it could change meaning – for example after return, or before a line starting with ( or [ – so code without semicolons keeps working.
Professional tools such as esbuild and Terser also shorten variable names and remove unused code, which saves more. Use them in your build process for large applications.
Tips for the best results
- Keep the original file for editing and debugging.
- Keep /*! comments to preserve licence notices for libraries.
- Test the minified script in the browser before deploying it.
- For large apps, a bundler such as esbuild or Terser saves more by renaming variables.
Common mistakes to avoid
Minifying TypeScript or JSX
Compile to plain JavaScript first.
Expecting obfuscation
Minified code is still readable. Do not put secrets in client-side JavaScript.
Pasting partial code
An unfinished string or comment at the end causes an “Unterminated” error.
JavaScript Minifier – frequently asked questions
Is this minifier safe for code without semicolons?
Yes. Line breaks are kept wherever they might act as a semicolon.
Does it rename variables?
No. Renaming saves more space but can break code that depends on names. This tool only removes comments and whitespace.
Does it support modern JavaScript?
Yes: template literals, arrow functions, classes, private fields, optional chaining, BigInt and regex literals are all handled.
Why is my error “Unterminated string”?
A quote, backtick or regular expression was opened but not closed. Check the code runs in your browser first.
Does it work with ES modules?
Yes. import and export statements are minified like any other code.
Will minifying fix bugs?
No. It keeps behaviour the same, including bugs.
Why is my minified file only a little smaller?
Code that has few comments and short indentation has little to remove. Tools that rename variables can save more, at the cost of readability.
Can I un-minify JavaScript?
You can re-indent it with a code formatter in your editor, but removed comments cannot be restored – always keep the original.