JavaScript Minifier

Minify JavaScript online: strip comments and collapse whitespace to shrink JS code into one line, then copy it. Runs in your browser.

Runs in your browser. Files never leave your device.
10 words · 71 chars

About the JavaScript Minifier

This page minifies JavaScript by stripping comments and squeezing every run of spaces, tabs and line breaks down to a single space. That's often all you need for an inline <script> tag, a bookmarklet, a code snippet in a CMS field or a small widget, where setting up a full build step would be overkill.

Paste the code and the compact version appears at once, ready to copy. Processing happens in your browser as you type, so scripts with API keys or private logic stay on your device.

What the minifier removes

There are three passes. The first deletes line comments: everything from // to the end of each line. The second deletes block comments, from /* to the next */, including JSDoc blocks that span several lines. Finally it replaces each group of whitespace characters (spaces, tabs, newlines) with one space and trims the start and end.

Nothing else is touched. Variables aren't renamed, function names aren't shortened, dead code stays and expressions aren't rewritten, so the output is still readable enough to debug and no optimiser ever changes your logic. For a production bundle you would still run a full minifier in your build; this page is for the quick jobs in between.

Before minifying, the tool checks that the input looks like JavaScript (keywords such as function, const or return, arrow functions, braces, semicolons or console calls). If it finds none, it shows a warning instead of output. The check is loose: ordinary English that contains words like if, for or this passes it, so it catches empty or random input rather than proving the code is valid.

Assumptions and limits

  • Put a semicolon at the end of every statement. Because line breaks become spaces, code that relies on automatic semicolon insertion (const a = 1 on one line, const b = 2 on the next) joins into one line that won't run.
  • Any // inside a string is treated as a comment. A line such as const api = "https://example.com/v1"; is cut after https:, so move URLs into a separate file or minify that part by hand.
  • A block comment that contains // on the same line as its closing */ (for example /* see http://x.com */) loses its end marker in the first pass, and the second pass then deletes everything up to the next */ in the file, including real code. Remove such comments, or the URL in them, before minifying.
  • Whitespace inside strings and template literals is collapsed too, so a multi-line template string becomes one line with single spaces.
  • License comments (/*! ... */) are removed along with all other comments; add them back at the top if your licence requires it.
  • Code is not checked for syntax errors. If the original has a bug, the minified version has the same bug.

Worked examples

Compress a JS function with comments

A 112-character snippet with a JSDoc block, a line comment inside the function and a trailing comment shrinks to 61 characters, about 46% smaller. Every comment is gone and the code sits on one line.

/**
 * Add two numbers.
 */
function add(a, b) {
  // quick sum
  return a + b;
}

const total = add(2, 3); // 5

→ function add(a, b) { return a + b; } const total = add(2, 3);

The sample code on the page

The greet() function the tool loads with is 71 characters across four lines. Minified it becomes 67 characters on one line. Indented code without comments saves less, because only the line breaks and leading spaces can go.

function greet(name) { console.log("Hello " + name); return true; }

Where minification goes wrong

Leave out the semicolons and two statements join into const a = 1 const b = 2, a syntax error. Add them back, minify again, and the result runs.

What is removed and what is kept

In your codeAfter minifying
// line commentsRemoved, up to the end of the line
/* block */ and /** JSDoc */ commentsRemoved, even across several lines
Indentation, tabs, blank linesRemoved
Line breaks between statementsReplaced with a single space
Single spaces around = + ( {Kept
Variable and function namesKept unchanged
Text inside stringsKept, but runs of spaces become one space and // ends the line

How to use the JavaScript Minifier

  1. Replace the sample greet() function. Clear the input box and paste your script or snippet; the character count under the box shows the original size.
  2. Read the result box. The minified JavaScript updates on every keystroke. A warning that no JavaScript was detected means the box holds no recognisable keywords, braces or semicolons.
  3. Copy and test. Press Copy, paste the one-line code where it belongs and load the page once to confirm it still runs.

Frequently asked questions

How do I minify JavaScript without installing anything?

Paste the code into the input box on this page. Comments and extra whitespace are stripped immediately, and the Copy button puts the result on your clipboard. There's nothing to install and no settings to choose.

Does this JS minifier rename variables or mangle code?

No. It only removes comments and collapses whitespace. Names, logic and the order of statements stay exactly as you wrote them, which also means the size saving is smaller than a full build-tool minifier that renames variables.

Why does my minified code throw a syntax error?

Usually a missing semicolon or a // inside a string. Separate lines are joined with a space, so statements without semicolons run together, and a URL or any other // in a string is read as a comment. Add the semicolons and keep strings with // out of the minified part.

How much smaller will my JavaScript file get?

Anywhere from a few percent to 40% or more, depending on how much of the file is comments and indentation. Heavily commented, deeply indented code is at the top of that range. Code that is already compact saves little, since names and operators are untouched.

Can I minify a whole JS file or several files at once?

Not as files, because there is no upload. Open the .js file in an editor, copy its contents into the box, and copy the result back. For several files, minify them one after another, or combine them first if they load together.

Is my code sent anywhere when I compress JS here?

No. The minifying is done by JavaScript running in your own browser tab, so your source code, keys and comments are not uploaded to a server or stored by VelixaKit.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.