JavaScript Minifier
JavaScript Minifier
Light, string-safe JavaScript minifier.
Runs entirely in your browser
How to use this tool
- Fill in the inputs.
- Read the result.
- Copy or download as needed.
About the JavaScript Minifier
The JavaScript Minifier reduces the size of JavaScript code by removing comments and unnecessary whitespace, while deliberately leaving string contents, template literals, and variable names untouched. Paste your JavaScript code, click Minify, and get a smaller, functionally identical version of the same script.
This is a lightweight minifier by design — it focuses purely on safe, low-risk size reduction rather than advanced optimizations like variable renaming or dead code elimination, which require a much deeper understanding of the code's structure and carry more risk of accidentally changing behavior.
The minifier scans through your code character by character, carefully tracking whether it is currently inside a single-line comment, a block comment, or a string literal (single-quoted, double-quoted, or backtick template literal), since whitespace and comment syntax inside a string must never be touched — removing a space inside a string would change the actual text your program produces. Comments are stripped entirely, and any whitespace between meaningful tokens outside of strings is removed, while a single space is preserved between two adjacent word characters (like two keywords) to prevent them from being accidentally merged into an invalid single token.
After minifying, the tool runs a safety check by attempting to parse the minified result as a valid JavaScript function using the `Function` constructor; if this check fails, it means something went wrong during minification (most often due to unusual syntax the simple character-scanning approach did not anticipate), and the tool reports a syntax error rather than handing you code that might be broken.
Common use cases
- Reducing the file size of a JavaScript file before deploying it to a website to improve load time.
- Quickly minifying a small script or snippet without needing to install build tools like webpack or Terser.
- Stripping comments from JavaScript before sharing a script publicly.
- Getting a rough sense of a script's minified size compared to its original, commented, formatted version.
- Minifying a simple utility script for embedding directly in an HTML page.
Tips and best practices
- This minifier does not rename variables or perform advanced code optimizations, so for production applications with strict size requirements, a dedicated build-tool minifier (like Terser) will typically achieve significantly smaller output.
- Because the tool performs a syntax check after minifying, a reported error usually means the minified code is not valid — check your original code for unusual syntax patterns if this happens.
- Comments are removed entirely and cannot be recovered, so always keep your original, commented source file as your working copy.
- This lightweight approach is a good fit for quick, occasional minification needs rather than as part of an automated production build pipeline for a large application.