What is javascript minifier?
A minifier makes code smaller by removing things the browser does not need, such as comments, indentation and blank lines. Smaller scripts download faster and help page speed scores.
This tool uses a careful approach: it keeps strings intact, removes comments and trims whitespace, and it keeps line breaks so that code relying on automatic semicolons still works.
How to use the javascript minifier
- Paste your JavaScript.
- Check the size savings.
- Copy the result and test it before use.
How the javascript minifier works
The code is scanned character by character. Text inside quotes and template strings is copied as is. Line comments and block comments are dropped. Spaces and tabs are trimmed and spaces around common punctuation are removed.
Worked example
Common uses of the javascript minifier
- Shrinking a small script for a landing page.
- Cleaning code snippets before sharing.
- Learning how minification works.
- Quick fixes without a build tool.
- Reducing inline script size.
Tips and common mistakes
For large projects, use a build tool such as esbuild or Terser for variable renaming and dead code removal.
Always test minified code, especially if it contains regular expressions with slashes.
Background: what to know before you rely on it
Minification is part of front end performance. Every kilobyte of script must be downloaded, parsed and run, which matters most on slow phones and networks. Full minifiers shorten names and remove unreachable code, saving much more than whitespace removal. A safe whitespace and comment pass is still useful for small sites that do not have a build step. Combine it with server compression and caching for the best result, and keep original source files for editing.
Private, free and fast
This tool runs entirely in your browser. What you type or choose is not uploaded to a server and is not saved after you close the page, which keeps it fast and private. It is free to use as often as you like. See more in all developer tools, or browse the full list of tools.
Field by field guide
- JavaScript code: Type or paste your text here. Use a new line for each entry where the label says so.
Change one field at a time to see how the result responds, and use the worked example above to check that you get the same answer.
What a JavaScript minifier can and cannot do
A basic minifier strips comments and unnecessary whitespace. It does not rename variables or remove dead code the way a full build tool does.
Practical scenarios
- Shrinking a small tracking or widget snippet before pasting it into a page.
- Testing how much a hand written script shrinks before you set up a build pipeline.
- Producing a bookmarklet that fits in a single line.
Common mistakes
- Relying on automatic semicolon insertion. Add semicolons before you minify so lines join safely.
- Minifying code that depends on function names, such as some frameworks. Test the result.
- Treating minified output as source code. Always keep the original file.
Shipping less JavaScript
JavaScript costs more than its download size, because the browser must parse and run it. Smaller scripts help both.
Expert tips
- Defer non critical scripts so they do not block rendering.
- Remove unused libraries.
- Combine small files to reduce requests when using HTTP 1, and not when using HTTP 2.
- Use a build tool with tree shaking for large projects.
- Serve compressed files with long cache lifetimes.
For measurable gains, test with Lighthouse and look at total blocking time.
Frequently asked questions
Is it safe?
It is conservative, but test your output. Unusual regular expressions can confuse any simple minifier.
Does it rename variables?
No. That needs a full parser.
Does it keep line breaks?
Yes, to protect code that relies on automatic semicolon insertion.
Is my code uploaded?
No.
Related tools
CSS Minifier
Paste your CSS and the minifier removes comments and extra whitespace to make the file smaller, with the...
Developer ToolsHTML Minifier
Paste your HTML and the minifier removes comments and extra whitespace between tags to reduce file size...
Developer ToolsJSON Minifier
Paste JSON to remove all extra spaces and line breaks. The tool validates the data first and shows how...
Developer ToolsSVG Optimizer
Paste your SVG code and the optimizer strips comments, metadata and editor leftovers and rounds long...
Developer ToolsJSON Formatter and Validator
Paste your JSON and the tool checks that it is valid, then formats it with indentation or compresses it...
Developer ToolsBase64 Encoder and Decoder
Base64 turns text or bytes into a safe string of letters and numbers. Choose encode or decode, paste...
Results are for information and education. For legal, financial, medical or security decisions, check with a qualified professional. Do not paste live secrets into any website.