JavaScript Minifier
Safe minifier: strips comments and whitespace, keeps line breaks where JavaScript needs them (ASI). It does not rename variables.
FREE TOOL · NO SIGN-UP
A JavaScript minifier removes comments, indentation and unnecessary whitespace from JS code so the file downloads and parses faster without changing what it does. Paste your script into the tool above and click Minify JavaScript. You get the compressed code, the original and minified size in bytes or KB, the percentage saved and a quick syntax check, ready to copy or download as script.min.js.
What JavaScript Minification Does
Readable JavaScript is full of characters the browser does not need: spaces for indentation, blank lines between functions and comments explaining the logic. Minification strips those out. The browser runs the minified script exactly as it would run the original, but there are fewer bytes to send over the network and fewer characters to parse.
That matters because JavaScript is often one of the heaviest parts of a modern page. Large scripts can be render-blocking, delay interaction and push up metrics like Total Blocking Time and Interaction to Next Paint. Shrinking the files is one of the simplest ways to reduce that cost.
Minification is a standard step for production code. Developers keep the readable source for editing and serve a minified version to visitors. Most build tools do this automatically, but an online minifier is handy for quick jobs: a snippet for a WordPress theme, a tracking script, a widget, or a file from a project without a build pipeline.
This tool is a safe minifier. It focuses on removing what is clearly unnecessary and leaves anything that could change behavior alone, which keeps the risk of breaking your code low.
How the Minifier Shrinks Code
The minifier reads your code token by token. It recognizes strings, template literals, regular expressions, comments, identifiers and operators, so it knows the difference between a // inside a string and a real comment. It then rebuilds the code with only the spaces and line breaks JavaScript actually needs.
Removing whitespace, comments and semicolons
All line comments and block comments are removed. The one exception is license comments that begin with /!, which are kept by default because many open-source licenses require the notice to stay with the code. Untick “Keep /! license */ comments” if you do not need them.
Spaces and tabs are removed except where two words would otherwise merge, such as between “return” and a value. Line breaks are removed too, but the tool keeps a line break wherever JavaScript’s automatic semicolon insertion (ASI) depends on it. That protects code written without semicolons from being joined into something that means a different thing.
The tool does not add or remove semicolons. Your code keeps its existing semicolon style, which is one reason the output stays safe.
Variable mangling and dead code
Advanced minifiers such as Terser, UglifyJS and esbuild go further. They rename local variables to single letters (mangling), remove code that can never run (dead code elimination), inline constants and rewrite expressions into shorter forms. This produces much smaller files.
This tool does not do any of that. It does not rename variables, change logic or remove unused code. The output is smaller than the original, but less compressed than a full build tool would produce. The benefit is that variable names stay readable and nothing about how the code behaves changes.
If you need maximum compression for a large application, use a build tool. For snippets and small scripts, safe minification gets most of the easy savings.
How to Minify a Script in Three Steps
Paste your JavaScript. Copy the code into the JavaScript box. It can be a whole file, a function or an inline script.
Choose whether to keep license comments. Leave the option on if the code includes third-party libraries with /*! license headers. Turn it off for your own code if you want every comment removed.
Click Minify JavaScript and check the results. The stats show the original size, the minified size and the percentage saved. A message under the stats confirms “Syntax check passed” when the output parses, or warns you if there is a syntax error. Click Copy to use the code, or Download to save script.min.js.
The syntax check runs the output through the browser’s own parser without executing it. ES modules that use import or export cannot be checked this way, so you may see a warning for module code even when it is valid. In that case, test the minified file in your project.
Everything runs locally in your browser. Your code is not uploaded anywhere.
Effect on Page Speed and Core Web Vitals
Smaller scripts download faster, especially on slow mobile connections. They also take slightly less time to parse. Both help pages become interactive sooner.
Be realistic about the size of the gain. Minification shrinks the text of a script, but the biggest JavaScript costs usually come from how much code runs, not how many characters it has. A large framework or a stack of third-party tags will still be heavy after minification.
For better Core Web Vitals, combine minification with:
- Removing scripts you no longer use.
- Loading non-critical scripts with defer or async so they do not block rendering.
- Splitting large bundles so pages only load the code they need.
- Delaying third-party tags such as chat widgets until after the page loads.
Minify first because it is quick and safe, then work on these bigger wins.
Minification, Compression and Bundling
These three steps are related but different.
Minification removes unnecessary characters from the code itself.
Compression such as Gzip or Brotli is applied by the server when the file is sent, and decompressed by the browser. It reduces transfer size a lot, and minified code compresses slightly better than unminified code. Check that your server or CDN has it enabled by looking for a Content-Encoding header in your browser’s developer tools.
Bundling combines many small files into fewer larger ones, which tools like webpack, Rollup and esbuild handle. It reduces the number of requests and lets the bundler remove unused code across files.
A production setup usually does all three: bundle, minify, then serve with compression. For other assets, use the CSS Minifier and HTML Minifier.
Source Maps for Debugging
Minified code is hard to debug because errors point to a line and column in a compressed file. Source maps solve this. A source map is a separate file that maps each position in the minified code back to the original source, so browser developer tools can show you the readable version.
Build tools like Terser, esbuild and webpack generate source maps automatically. This online minifier does not, since it is designed for quick one-off jobs. Because it does not rename variables, its output is still fairly easy to read when you reformat it with the JavaScript Beautifier.
Mistakes That Break Minified Scripts
Minifying code with syntax errors. If the original is broken, the output will be too. Fix errors first; the syntax check helps you spot them.
Concatenating files without semicolons. Joining two scripts where the first does not end in a semicolon can merge statements. End each file with a semicolon before combining.
Minifying already minified code. It usually saves nothing and can make debugging harder.
Removing required license notices. Keep /*! comments for third-party code.
Editing the minified file. Always change the original, then minify again.
Not testing after deploying. Run through the features that use the script, and check the browser console for errors.
Double minification in WordPress. A theme, a caching plugin and a CDN all minifying the same file can cause conflicts. Use one.
When a Build Tool Like Terser Fits Better
Use a build tool when you manage a large codebase, deploy often, or need the smallest possible files. Terser is the standard choice for production minification in many JavaScript projects, and esbuild is popular for its speed. Both can mangle variable names, drop dead code, generate source maps and run automatically every time you build.
Use this online minifier when you need a quick result without setting anything up: a snippet for a site header, a small script for a landing page, a check of how much a file can shrink, or a project that does not have a build step.
Minification Versus Obfuscation
Minification makes code smaller. Obfuscation makes code hard for people to understand, by renaming everything, encoding strings and adding confusing structures. Obfuscation can make files larger and slower. Neither protects secrets: anything sent to the browser can be read with enough effort. Never put API keys or passwords in client-side JavaScript.
Faster Scripts, Smoother Pages
Minify scripts here, measure the size of any snippet with the Byte Counter, and tidy your markup with the HTML Minifier. For more developer and SEO utilities, browse the FHSEO Hub free SEO tools collection.
