JavaScript Minifier

Remove comments, whitespace, and blank lines from JavaScript to reduce file size and speed up your website.

What is JavaScript Minification?

JavaScript minification is the process of removing all unnecessary characters from JavaScript source code without changing its functionality. This includes removing whitespace, line breaks, comments (both single-line // and multi-line /* */), and collapsing redundant space around operators and punctuation.

The result is a functionally equivalent script that is significantly smaller in file size. While minified code is difficult for humans to read, it is perfectly understood by JavaScript engines in browsers and on servers (like Node.js). The reduced size means the browser downloads the script faster, parses it more quickly, and begins executing it sooner.

Minification is a standard step in every modern front-end build pipeline. Tools like Webpack, Rollup, Vite, and Parcel all minify JavaScript automatically in production builds using algorithms that go beyond simple whitespace removal — they also rename local variables to single letters, eliminate unreachable ("dead") code, and inline small functions. Our tool focuses on the core whitespace and comment removal, making it ideal for quick, one-off minification without a full build setup.

According to Google's web performance guidelines, render-blocking JavaScript is one of the most common causes of poor page load times. Serving minified scripts directly reduces the time to first byte (TTFB) and the overall script evaluation time, positively impacting Core Web Vitals metrics like First Contentful Paint (FCP) and Time to Interactive (TTI).

How to Use This JavaScript Minifier

  1. Paste your JS code: Copy your JavaScript source file or code snippet and paste it into the left text area.
  2. Click "Minify JS": The tool strips all comments and excess whitespace and displays the compact result on the right.
  3. Copy the output: Use the Copy Output button to copy the minified code. You can then save it as a .min.js file or embed it directly in a <script> tag.
  4. Use in production: Serve the minified file instead of the original from your web server. Keep the original source file for development and maintenance.

Note: For complex, production-grade projects with module bundling, tree-shaking, and source maps, consider using a dedicated build tool like Webpack or Vite. This tool is ideal for simple scripts and quick optimisations.

Why Minify JavaScript?

  • Faster Downloads: A script that is 50% smaller downloads in half the time, especially important for users on mobile networks.
  • Improved PageSpeed Scores: Google PageSpeed Insights and Lighthouse flag un-minified JavaScript as a performance opportunity. Minifying scripts is an easy win for your score.
  • Reduced Bandwidth Costs: High-traffic websites serve scripts to millions of users. Even a 30KB reduction per script can save terabytes of bandwidth monthly.
  • Faster Script Parsing: JavaScript engines parse code character-by-character. Removing whitespace means the parser does less work before execution can begin.
  • Basic Obfuscation: While minification is not a security measure, it does make your code slightly harder to casually read and copy.

JavaScript Minification Example

Before — Readable JavaScript
// Greeting function
function greet(name) {
    // Log greeting to console
    console.log('Hello, ' + name + '!');
}

greet('World');
After — Minified JavaScript
function greet(name){console.log('Hello, '+name+'!');}greet('World');

To expand minified JavaScript back to a readable format, use our JavaScript Beautifier tool.