Developer

JavaScript Minifier

Minify JavaScript by removing comments, trimming whitespace, and outputting cleaner code instantly in your browser.

Loading interactive tool…

Embed this tool on your site

About this tool

JavaScript Minifier shrinks JS source with lightweight text rules rather than a full parser. Paste your code and the output updates as you type, with input and output byte counts. Drop comments (on by default) removes block comments and line comments that follow a name, number or closing bracket; Drop console.log lines deletes lines that contain only a simple console.log(...) call; Keep one-line output joins everything onto a single line. Otherwise line breaks are kept and spaces are removed wherever they are not needed between words. It does not rename variables, remove dead code or rewrite syntax. Known limitation: a // comment that follows {, ;, (, a comma or an operator, or starts the file, is kept as code — and with Keep one-line output it then comments out the rest of the script. Code that relies on automatic semicolon insertion can also break in one-line mode. Test the output before deploying it. Everything runs in your browser.

Why use it

  • Reduces Parse and Execution Time: The browser must parse every byte of JavaScript before it can build the call graph. Smaller scripts parse faster, unblocking the main thread sooner and improving Total Blocking Time — one of Google's Core Web Vitals metrics.

  • Block Comment Stripping: /* */ blocks and JSDoc annotations are removed, along with line comments that follow a name, number or closing bracket.

  • Optional console.log Removal: Drop console.log lines deletes standalone console.log(...) lines so debug output does not ship.

  • Single-Line Mode: Keep one-line output joins the code onto one line for bookmarklets and inline snippets — check that no // comment remains first.

  • Works Without a Build Tool: Projects that ship plain JS files without Webpack, Rollup, or esbuild still need minification before production. This tool provides the final compression step with a paste-and-copy workflow.

  • Exact Byte Counts: Input and output byte counters let you measure the impact of minification on your script and decide whether code splitting or tree-shaking is worth the effort.

How to use

  1. Paste your JavaScript source code into the left input panel.
  2. The minified output appears as you type, with Input bytes and Output bytes counters below.
  3. Tick or untick Drop comments, Drop console.log lines and Keep one-line output to choose the transformations.
  4. Check the output for // comments that were kept, especially before using Keep one-line output, and run your tests on the result.
  5. Click the Copy button on the output to copy the minified JS.
  6. Click Clear to empty the input and reset the options.

When it helps

  • Before deploying a custom JS utility, analytics snippet, or widget to a production website or CDN.
  • When inlining a small JavaScript snippet directly in HTML and needing to keep the <script> block compact.
  • After writing a bookmarklet or userscript that must fit in a browser bookmark URL or be pasted into a console.
  • When a Lighthouse audit reports unused JavaScript or large JS payloads as opportunities and you want to measure the minification contribution.
  • Before embedding a JS snippet in a third-party tag manager like Google Tag Manager where script size affects page load.
  • When distributing a JavaScript library or widget that other developers will load from a CDN — providing a .min.js alongside the source is the standard distribution pattern.

Examples

Function with a JSDoc block

Input
/**
 * Add two numbers.
 */
function add(a, b) {
  return a + b;
}
Expected result
function add(a,b){
return a+b;
}

Drop console.log and keep one line

Input
function greet(name) {
  console.log('greet', name);
  return 'Hi ' + name;
}
Expected result
function greet(name){return'Hi '+name;}

Arrow function with optional chaining (one line)

Input
const getDisplayName = (user) => {
  /* full name first, then username */
  return user?.profile?.fullName ?? user?.username ?? 'Anonymous';
};
Expected result
const getDisplayName=(user)=>{return user?.profile?.fullName??user?.username??'Anonymous';};

Tips

  • Never commit minified JS to version control as your primary source — keep the readable original and generate the .min.js as a build artefact.
  • If the one-line output throws a SyntaxError, look for a // comment that was kept or a missing semicolon at the end of a line.
  • Bookmarklets must start with javascript: and fit on one line — run your bookmarklet code through this minifier first, then prepend the protocol.
  • For inline analytics or tag manager snippets, compare the Input bytes and Output bytes counters, then estimate gzip size to see the real network cost.
  • When minifying third-party code for inspection or embedding, check its license first — some open-source licenses require retaining the original copyright comment block.

Frequently Asked Questions

Will minification break my JavaScript logic?
It can. The tool only removes comments and whitespace, without renaming anything, but it uses simple text rules. A // comment after {, ; or ( is kept, and with Keep one-line output it comments out the remaining code; code without semicolons can also break when joined onto one line. Run your tests on the output.
Does the minifier support modern JavaScript like optional chaining and async/await?
It does not transform syntax, so optional chaining, nullish coalescing, logical assignment, async/await and class fields pass through with only whitespace and comments removed.
What is the difference between minification and obfuscation?
Minification reduces file size by removing non-essential characters and shortening local names. Obfuscation intentionally makes code hard to understand by scrambling identifiers and inserting misleading patterns. This tool minifies; it does not obfuscate.
Will eval() or Function() calls cause problems after minification?
Not because of renaming — this tool never renames variables, so names used inside eval strings stay valid. String contents are left as they are.
Should I minify before or after bundling?
Minify after bundling. Bundlers like Webpack and esbuild can eliminate dead code (tree-shaking) across modules before minifying the result. Minifying individual files first doesn't enable cross-module dead-code elimination.
Can I use source maps with the minified output?
This tool does not generate source maps. If you need source maps for production error tracking via Sentry or similar tools, use a build tool like esbuild or Terser with source map support enabled.
Does the minifier handle strict mode and ES modules?
'use strict' strings and import/export statements are left as written; only the whitespace and comments around them change.
How does minification interact with gzip compression on the server?
They compound: minification reduces file size by 40–60%, then gzip reduces it a further 60–80%. A 100 KB script might minify to 55 KB and then compress to 15 KB on the wire — a 85% total reduction.

Explore the category

Glossary

Minification
Transformation of JavaScript source code to remove whitespace, comments, and rename local variables to the shortest possible identifiers, reducing file size without changing runtime behaviour.
Tree Shaking
A dead-code elimination technique used by module bundlers that removes exported functions and variables that are never imported by any module in the bundle, reducing total script size.
Total Blocking Time (TBT)
A Core Web Vitals metric measuring how long the main thread is blocked by JavaScript parsing and execution during page load. Smaller, faster-parsing scripts reduce TBT.
Source Map
A .map file that maps positions in minified/bundled output back to their original source locations, enabling browsers and error trackers to display meaningful stack traces from minified production code.
Terser
The de facto standard JavaScript minifier used by Webpack, Vite, and esbuild. It performs whitespace removal, dead code elimination, and identifier shortening, producing the smallest safe output of any current open-source minifier.
Dead Code Elimination
Removal of code that can never be reached or executed — for example, the false branch of if (false) {...} or functions that are defined but never called. Applied by advanced minifiers as a size optimisation.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.

Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.

✓ Free to use✓ No sign-up✓ 500+ possibilities