Developer Tool updated 2 hours ago

Javascript Minify

JavaScript Minify removes comments and unnecessary whitespace from a script, shortens a few common expressions and returns a smaller file you can copy or download. Paste code or fetch a public URL; processing runs on the server, up to 200,000 characters per run.

JavaScript Minify Compact JS Fast Processing Developer Tool

Use Javascript Minify

Paste a direct code file URL to load its contents into the editor.

Output

Done
72
Time Used
67
Total Users
5+ years
Served
Last reviewed in 1 week ago. Usage numbers are refreshed during periodic audits. (Reporting since 21 Feb 2022)
Report a mismatch

Read Content

Learn how the tool works and when to use it.

What this page is for

A readable script carries comments, indentation and spacing that the JavaScript engine does not need. This page sends the source to a server-side minifier and returns a compact version, with character counts for both sides. It is a source-to-source pass: JavaScript in, JavaScript out, with no execution and no bundling.

The page opens with JavaScript and Minify already selected. The language and mode selectors remain visible, so you can switch to another language or to Beautify, but everything below describes the JavaScript minifier.

What the minifier removes

Single-line comments and block comments are stripped. Extra spaces, tabs and indentation are collapsed. Unlike a full compressor, this minifier often keeps line breaks where they separate statements, so the output is not guaranteed to be one long line. In testing, a small script kept its statement breaks and only lost its indentation and comments.

Strings, template literals and regular expressions are extracted before the whitespace pass and restored afterwards. That protects comment-like text inside a URL, a regular expression or a string. A value such as "https://example.com" keeps its double slash instead of being mistaken for a comment.

Two rewrites you will notice

The minifier does more than delete whitespace. It also applies two small transformations:

  • Property notation: a bracket access with a valid identifier, such as record["name"], can become record.name. The meaning is the same and the result is shorter.
  • Boolean shortcuts: true becomes !0 and false becomes !1. These are valid JavaScript expressions that evaluate to the same values.

Neither rewrite renames your variables. A function called calculateTotal still appears as calculateTotal in the output. That makes the result easier to debug than a mangled bundle, but it also means the savings are smaller.

What it does not do

It does not rename or mangle identifiers, remove dead code, tree-shake modules, merge files, transpile newer syntax or generate source maps. It does not resolve imports or understand a bundler's module graph. It also does not validate your code: a script with a syntax error may pass through and fail only when the browser loads it.

If you need those features, use a build tool such as esbuild, Rollup or webpack. This page is for a quick shrink of a single file, not for producing a production bundle.

Strings, regular expressions and URLs

Comment stripping is the riskiest part of any regex-based minifier. A regular expression can contain two slashes, and a string can contain text that looks like a block comment opener. The library extracts these regions before it strips comments, so ordinary cases are handled. Complex or unusual patterns are still worth testing, especially regular expressions built from strings or split across lines.

If a script breaks after minification, compare the two versions around every regular expression and every string that contains punctuation. That is where a conservative minifier is most likely to differ from a parser-based one.

Modern JavaScript

Arrow functions, optional chaining, nullish coalescing, template literals and class fields passed through in testing. The minifier treats them as text and does not try to transform them. That is good news for modern code, but it is not a compatibility guarantee. Run the minified script in the browsers you support and check the console.

Automatic semicolon insertion is another area to watch. The minifier kept statement breaks in the cases tested, so a return followed by a value on the next line stayed intact. Do not rely on that for every construct: write explicit semicolons in code that will be minified, and test anything that depends on a newline.

Fetching a script from a URL

The URL tab asks the server to download a public script and place it in the editor. The fetch is capped at 200,000 characters. CDN links usually work; authenticated links, bot-protected links and signed URLs usually do not. The server fetches the raw response, so an HTML error page will arrive as HTML and produce a JavaScript syntax error rather than a useful result.

Step by step

  1. Paste the script into Manual Code, or load it through the URL tab.
  2. Confirm the language is JavaScript and the mode is Minify.
  3. Press Process Code.
  4. Compare the character badges and skim the output for the two rewrites described above.
  5. Copy the result, or download it as minify-output.js.
  6. Run the script in a test page and check the browser console before deploying it.

How much smaller will it be

A heavily commented, generously indented script can lose a meaningful share of its bytes. A file already processed by a bundler may lose very little, because the comments and whitespace are already gone. The exact number depends on comment density, identifier length and how much spacing the source used.

Do not treat the percentage as a quality score. A small file that still works is better than a large reduction that breaks an edge case.

Debugging minified JavaScript

Without a source map, a stack trace points into a compact file where many statements share a line. Keep the original source and deploy source maps from your build whenever possible. If you inherit a minified file with no source, beautify a copy to restore line breaks, then work from that copy. Beautifying cannot recover comments or the original names, and the JavaScript Beautify page has limits with modern syntax, so test the result.

Common errors

An empty output usually means the input was empty or the request exceeded the character cap. A syntax error after minification often comes from a regular expression that the extractor did not recognise, or from a template literal containing an unusual sequence. A script that runs but behaves differently often points to a newline-sensitive construct. Revert to the original and narrow down the section that changed.

Limits and privacy

One script per run, 200,000 characters maximum, JavaScript mode on this page. The code is sent to the server for processing and returned in the response; the tool does not store it. Large bundles belong in a local build step, where minification can run with source maps and the rest of the pipeline.

A worked example

To show what the minifier actually returns, this short function was passed through the same server-side library the page uses. The input was 355 characters, including a line comment, a block comment and four-space indentation:

// Calculate cart total
function cartTotal(items, discount) {
    /* skip empty carts */
    if (items.length === 0) {
        return 0;
    }
    let total = 0;
    for (const item of items) {
        total += item["price"] * item.qty;
    }
    const hasDiscount = discount > 0 ? true : false;
    return hasDiscount ? total * (1 - discount) : total;
}

The output was 210 characters, roughly 41 percent smaller:

function cartTotal(items,discount){if(items.length===0){return 0}
let total=0;for(const item of items){total+=item.price*item.qty}
const hasDiscount=discount>0?!0:!1;return hasDiscount?total*(1-discount):total}

What changed, line by line

  • Both comments are gone, and the indentation and spaces around operators were collapsed.
  • item["price"] became item.price, and true and false became !0 and !1.
  • The semicolon directly before a closing brace was dropped, as in return 0}. JavaScript does not need a semicolon at the end of a block, so this is safe.
  • The output still has three lines. The library kept some statement breaks rather than joining everything into one line.
  • Every name, including cartTotal, items and hasDiscount, is unchanged.

Use a small sample like this to check the minifier against your own coding style before you process a whole file. If your style differs, for example you leave out semicolons, run a similar test with a short excerpt first.

Frequently Asked Questions

FAQ

Short answers for the questions users ask before trusting the result.

No. The minifier does not mangle identifiers. It removes comments and whitespace and applies small expression shortcuts, so names stay readable.

This minifier is conservative and keeps many statement breaks. It is not a full compressor that forces everything onto one line.

Arrow functions, optional chaining, nullish coalescing and template literals passed through in testing, but test your own file. It does not transpile anything.

No. Strings, template literals and regular expressions are extracted before comments are stripped, so comment-like text inside them is protected.

No. Use a local build tool if you need source maps for debugging a production bundle.

No. Those are not plain JavaScript and may be corrupted. Compile them to JavaScript first, then minify the output.

The script is sent to the server for processing and returned in the response. The tool does not keep it after the request.

The minifier drops a semicolon that sits right before a closing brace, as in return 0}. JavaScript does not require one there, so the code still means the same thing.

Yes. The page opens on JavaScript and Minify, but the language and mode selectors stay visible. Choose another language before pressing Process Code. Each language is handled by its own formatter on the server.

Comments (0)

For user discussion, edge cases, and follow-up tips.
Leave a comment
Your comment will appear publicly after submission.
No comments yet. Be the first to comment!
Let Us Know!
Report an issue with this tool

Describe the issue you encountered so we can investigate and improve the tool.

What helps most
Include the input, expected result, actual result, browser/device, and a screenshot when helpful.
The screenshot button captures the page in the browser and attaches the generated image to this form.
Full-page screenshot
Captured in your browser with newisty.
No screenshot captured yet.
Tool Report