JavaScript Minifier - Free Online Tool

JavaScript Minifier strips comments and unnecessary whitespace from JS while preserving every string, regex literal, and identifier, so your bundle shrinks without changing how the code behaves.

Minify JavaScript

What is JavaScript Minifier?

JavaScript Minifier is a free, browser-based tool that compresses JavaScript by removing comments and collapsing whitespace at safe boundaries. The output is functionally identical to the input — every browser and Node.js runtime executes the minified version the same as the original — but the byte count drops, which translates to faster downloads, faster parse times, and lower bandwidth usage.

JavaScript Minifier is token-aware. Strings, template literals, and regex literals are preserved verbatim so their contents are never touched, and the minifier inserts a single space between tokens only when removing whitespace would change meaning (for example, between two identifiers, or after a return that would otherwise trigger automatic semicolon insertion). You can toggle comment removal off if you need to preserve licence banners or build-tool markers.

Typical users are developers preparing a small inline script for embedding in a Next.js page, engineers shaving bytes from a critical-path script tag, and authors of standalone JavaScript widgets that ship to many sites. The tool is a fast way to evaluate compression savings before deciding whether to add a dedicated minifier to your build pipeline.

How to Use This JavaScript Minifier

  1. Paste your readable JavaScript into the input textarea. Functions, modules, IIFEs, and inline snippets are all accepted.
  2. Decide whether to remove comments. Leave the option on for most production output; turn it off if your build relies on JSDoc, licence banners, or build-tool markers.
  3. Click Minify. JavaScript Minifier tokenises the source, drops comments and whitespace at safe points, and emits a compact version that runs identically.
  4. Read the size summary below the output. You will see how many bytes the input took, how many the minified output takes, and the percentage saved.
  5. Click Copy to send the minified JS to your clipboard and paste it into your inline <script> block, build artifact, or distribution file.
  6. Use Clear when you want to compress a different snippet so the input, output, and error states reset together.

Why Use This JavaScript Minifier?

  • Reduces JavaScript payload size, which improves Time to Interactive by lowering the parse and compile cost on slow devices.
  • Strips comments that should not ship to production, including JSDoc blocks, TODOs, and internal notes that inflate the response.
  • Preserves strings, template literals, and regex literals byte-for-byte so the minified code behaves identically to the source.
  • Inserts safe whitespace between tokens to avoid breaking automatic semicolon insertion in returns and short-circuit chains.
  • Runs locally in your browser, so proprietary scripts and unreleased modules never leave the device during compression.
  • Shows a byte savings summary after each run, making the value of minification visible at a glance.

When to Use JavaScript Minifier

  • Compressing a small inline analytics or feature-flag script before embedding it in the <head> of a marketing page.
  • Evaluating how much smaller a JavaScript module would be with comments removed and whitespace collapsed.
  • Shrinking a standalone widget that ships unmodified to dozens of customer sites without a build pipeline of its own.
  • Preparing a JS snippet for inclusion inside a JSON string, HTML data attribute, or build artifact where whitespace inflates the surrounding file.
  • Generating a single-file deliverable for a code interview, hackathon submission, or sandbox where every byte matters.
  • Cleaning up auto-generated JS before committing to version control so diffs reflect real changes rather than whitespace edits.

JavaScript Minifier Features

Token-aware compression

JavaScript Minifier classifies the source into strings, templates, regexes, comments, operators, and identifiers before emitting the output. That ensures it never collapses whitespace that would change semantics.

Comment removal toggle

Comments are removed by default. A toggle lets you keep them when JSDoc, licence banners, or build-tool markers must survive in the output.

String and regex preservation

Quoted strings, template literals, and regular expressions are emitted byte-for-byte. The tool never alters values inside them, only the whitespace around them.

ASI-safe whitespace

The minifier inserts a single space between tokens where removing whitespace would change parsing — for example, between two identifiers, or after a return statement. This protects against subtle automatic semicolon insertion bugs.

Byte savings summary

After each run, the tool displays input size, output size, and percentage saved. Use it to quickly judge whether minification is worth automating for your specific code.

Local-only processing

All compression happens in your browser. Your scripts are never transmitted, which keeps proprietary code and prerelease modules confidential.

How JavaScript minification saves bytes safely

JavaScript engines tokenize the source into a sequence of identifiers, operators, literals, and punctuation. Most whitespace between those tokens is purely for human readers — the engine ignores it. JavaScript Minifier removes that whitespace while preserving the spaces that are semantically meaningful, such as the space between two identifiers in `const a` or after a `return` that triggers automatic semicolon insertion.

The biggest pitfall in a naive minifier is misreading a regex literal as a division. A slash inside source code can start a regex (after `return`, `typeof`, or an opening bracket) or denote division (after an identifier or closing paren). JavaScript Minifier resolves the ambiguity with a small lookback rule so regex literals are emitted verbatim instead of being broken apart.

Comments are the simplest savings target. Line comments end at the next newline, and block comments end at `*/`. Both are removed by default, but a toggle lets you preserve them when JSDoc or licence headers must survive. Pair minification with gzip or brotli on the server and the delivered payload shrinks further — minified code compresses smaller than verbose code.

Decision Guide

Best for

  • Inline scripts and small widgets that ship without a build pipeline.
  • Quick estimates of how much minification would save in a project.
  • Compressing JS embedded inside JSON or HTML attributes.

Avoid when

  • You need full production minification with variable renaming — use terser, esbuild, or SWC.
  • Your dependencies require licence headers in the output (disable comment removal).

Example

Minify a JS snippet

Input

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

Output

function add(a,b){return a+b;}

JavaScript Minifier Best Practices

Minify in your build pipeline for production

JavaScript Minifier is great for one-off jobs. For production sites, use terser, esbuild, or SWC in the build pipeline so every release benefits from rename-and-dead-code-elimination optimisations on top of whitespace removal.

Keep a readable source of truth

Commit the readable version of scripts to version control so diffs are reviewable. Minify only as part of the build artifact, not the source files developers edit.

Preserve licence headers when required

Many libraries require licence attribution even in minified files. Turn off comment removal so licence headers survive, or use a build tool that supports preserve hints.

Pair minification with transport compression

Minification reduces the raw payload, but gzip and brotli compress further. The two stack, and minifying before compression typically produces the smallest delivered size.

Test the minified output

Run your tests against the minified bundle, not just the source. Subtle automatic semicolon insertion or strict-mode interactions occasionally surface only after minification.

Troubleshooting

Output still has spaces I did not expect.

Those spaces are kept on purpose to avoid breaking automatic semicolon insertion or merging two identifiers into one.

Licence header disappeared.

Turn off "Remove comments" so licence and attribution headers survive minification.

Common JavaScript payload problems JavaScript Minifier addresses

Inline scripts are larger than necessary

Inline analytics and feature-flag scripts often ship with comments and indentation. JavaScript Minifier removes that overhead so the <head> stays compact.

No build pipeline for a small widget

Standalone widgets and bookmarklets ship without a build system. The tool provides a quick way to compress the JS before distribution.

Developer comments slip into production

JSDoc, TODOs, and reminder comments often survive into deployed bundles. Minifying removes them in one pass.

Embedded JS inside JSON is bloated

When JS is embedded inside JSON or HTML attributes, whitespace doubles the cost because of escaping. Minifying first keeps the surrounding payload small.

Quick comparison of savings is needed

Before adding a minifier to a build pipeline, teams often want a quick estimate of the savings. This tool produces that number immediately.

FAQs

Does minified JavaScript behave identically to the original?

Yes. JavaScript Minifier only removes whitespace and comments that the engine ignores at parse time. Strings, template literals, regex, and identifiers are preserved exactly, and a single space is kept where removing whitespace would change parsing (for example, between two identifiers).

How does this compare to terser or esbuild?

Terser and esbuild are full production minifiers that also rename variables, fold constants, and eliminate dead code. This tool focuses on whitespace and comment removal — it is faster to run for one-off jobs and produces output that is easier to inspect, but the savings are smaller than what a full pipeline minifier produces.

Can it handle modern JavaScript features?

Yes. Template literals (including embedded expressions), regex literals, arrow functions, async/await, optional chaining, nullish coalescing, and spread syntax all pass through unchanged.

How much smaller will my JS get?

It depends on the source. Heavily commented and indented code can shrink by 30–50 percent. Already-compact code may shrink less. The tool reports the exact byte savings after each run.

What happens to my JSDoc and licence headers?

They are removed by default along with all other comments. Turn off comment removal if you need to preserve them, or use a build minifier with explicit preserve-comment hooks.

Is the tool safe for confidential code?

Yes. All compression runs in your browser. Your scripts are never uploaded, so internal code and prerelease modules remain confidential during the operation.

Can I undo the minification?

Yes, by running the output through JavaScript Beautifier on the same site. Round-tripping is safe as long as the input is valid JavaScript to start with.

Why is gzip already enabled — do I still need to minify?

Yes. Gzip and brotli compress repetitive text well, but minification removes bytes that compression would have to handle. The two techniques stack, and minifying before compression typically produces the smallest delivered payload.

Start using JavaScript Minifier

JavaScript Minifier shrinks scripts without changing how they behave — use it to ship lighter inline JS, evaluate compression savings, and prepare standalone widgets without a build pipeline.