Skip to main content

Free Online JavaScript Minifier

Strip whitespace and comments from JavaScript without changing behavior

Basic minification only (whitespace and comment removal). Does not mangle variable names or perform advanced optimizations.
Processed locally
Zero server requests
Works offline
Nothing leaves your device

Why use JavaScript Minifier

  • Shows original and minified byte counts side by side so you know the exact savings.
  • Supports ES2024 syntax -- optional chaining, nullish coalescing, async/await, top-level await.
  • Safe whitespace-only minification that never renames variables, so eval() and dynamic access keep working.
  • Your source code stays on your machine. Nothing is transmitted.

How it works

The minifier tokenizes your JavaScript source into its structural components -identifiers, keywords, operators, string literals, template literals, regular expressions, comments, and whitespace. All single-line (//) and multi-line (/* */) comments are removed first. Then every whitespace sequence between tokens is reduced: spaces are kept only where omitting them would merge two identifiers or keywords into one invalid token (e.g., 'return value' cannot become 'returnvalue'). Newlines are eliminated except where JavaScript's automatic semicolon insertion (ASI) rules require a line terminator to preserve meaning. String literals, template literals, and regex patterns are left untouched to avoid changing program behavior. The result is a single-line JavaScript string that the engine parses and executes identically to the original. No variable renaming or dead-code elimination is performed -this keeps the process safe for code using reflection or dynamic evaluation.

About this tool

How much of that JavaScript is whitespace and comments? Paste it here and find out. The minifier strips line breaks, indentation, block and inline comments, and unnecessary characters while preserving behavior. It shows you original and minified byte counts side by side so you can measure the savings. This performs safe, whitespace-only minification -- no variable renaming, no dead-code elimination -- so eval(), dynamic property access, and reflection all keep working. Handles modern ES2024 syntax: arrow functions, template literals, async/await, optional chaining, nullish coalescing, top-level await. For building a bookmarklet, embedding a tracking snippet in a site's <head>, or shrinking a WordPress custom script before enqueuing, this is faster than configuring Terser or esbuild. Paste, copy, done.

How to use JavaScript Minifier

  1. Paste your JavaScript. Drop the source code into the input area -- functions, modules, or full scripts.
  2. Read the compression stats. Original and minified byte counts appear with the percentage saved.
  3. Copy the output. Click Copy. Paste it into your <head> tag, bookmarklet, or deploy script.

Use cases

  • You're adding an analytics snippet to a site's <head> and want to minimize render-blocking bytes. Paste it in, copy the minified version.
  • A bookmarklet needs to fit complex functionality into a single URL-encoded string. Minifying first is what makes it short enough to work across browsers.
  • You wrote a custom WordPress script and need to shrink it before enqueueing. The Shopify theme also has asset size limits -- same workflow.
  • You're embedding a code sample in a web component and want to keep the inline script payload small. Minify before embedding.
  • A junior developer wants to understand what minification actually does. Paste readable code, see the output, compare line by line.
  • An ad tag widget script needs to be under a byte limit imposed by the ad network. Minify, check the count, submit.

Frequently Asked Questions

JavaScript minification removes unnecessary characters from JS source code -including whitespace, line breaks, comments, and sometimes shortens variable names -without changing the code's functionality. The result is a smaller file that browsers execute identically but download and parse faster.

JavaScript minification typically reduces file size by 20–60%, depending on the original code style and comment density. Well-commented, nicely formatted code sees the largest reductions. Popular libraries like jQuery see about 50% reduction from minification alone, with further gains from gzip/Brotli compression.

Properly implemented minification does not break code. It only removes characters that the JavaScript engine ignores. However, issues can arise with code that relies on Function.prototype.toString() or eval with specific formatting. Always test your minified code before deploying to production.

Minification focuses on reducing file size while keeping code functional and somewhat readable. Obfuscation deliberately makes code difficult to understand by renaming variables to meaningless characters, adding dead code, and transforming logic. Obfuscation is for intellectual property protection, not performance.

Yes. Minifying JavaScript is a standard production optimization. All major build tools -Webpack (Terser), Vite (esbuild), Rollup, and Parcel -include JS minification by default. This online tool is useful for quick one-off minification, embedded scripts, and projects without a build pipeline.

This tool processes standard JavaScript. TypeScript must first be compiled to JavaScript using the TypeScript compiler (tsc) or a bundler like Vite or esbuild. Once compiled to JS, paste the output here for minification. Most build tools combine TypeScript compilation and minification in a single step.

Tree shaking removes entire unused exports and functions from your code bundle, while minification removes unnecessary characters from the remaining code. Tree shaking requires ES module (import/export) syntax and is performed by bundlers like Webpack and Rollup. Both techniques are complementary for optimal file size.

JavaScript is the most expensive resource type on the web because it must be downloaded, parsed, compiled, and executed. Smaller JS files reduce download time, decrease parse/compile time, and reduce main-thread blocking -directly improving Total Blocking Time (TBT), Time to Interactive (TTI), and Interaction to Next Paint (INP).

With a basic whitespace-and-comment minifier, yes -no variable names are changed, so dynamic references remain intact. If you use a more aggressive minifier that mangles variable names (like Terser with full optimization), eval() and bracket notation with string literals can break because the referenced names no longer match. This tool performs safe minification without name mangling.

Minified code is harder to read in browser DevTools, but modern browsers support source maps that map minified code back to the original. For production deployments, generate a source map alongside your minified file. If you only need to quickly minify a snippet without a source map, keep the original copy somewhere safe so you can make future edits to readable code.

Removing whitespace and comments typically reduces file size by 20–40% for well-commented, readable code. If you add gzip or Brotli on top, the total reduction from original to compressed-minified is often 70–85% compared to original uncompressed. The exact amount depends heavily on how much whitespace and documentation your code contains.