JavaScript Minifier

Minify JavaScript by stripping whitespace, comments, and unnecessary characters. Copy or download the result without sending data anywhere.

Input
1
Output
1
0 characters 0 lines

JavaScript Minifier

This JavaScript Minifier removes unnecessary whitespace, comments, and line breaks from JavaScript code to produce the most compact representation. It reduces file size for faster page loads and lower bandwidth consumption.

The minification runs locally in your browser using the html-minifier library. Your code never leaves your device, making it safe for processing proprietary scripts, inline JavaScript, or any code that may contain sensitive logic.

How to use

  1. Paste your formatted JavaScript into the input editor.
  2. Click Minify JavaScript to strip whitespace and comments.
  3. View the compact code in the output editor.
  4. Use Copy for the clipboard, Download for a .js file, or Clear to reset both editors.

What is JavaScript minification?

JavaScript minification is the process of removing all characters from source code that are not required for correct execution. This includes stripping whitespace, removing comments, collapsing line breaks, and shortening variable names in advanced minifiers.

Minified JavaScript is standard practice in web development. Build tools like Webpack, Rollup, and esbuild include minification as a production step. This browser-based tool provides a quick way to minify individual scripts without a build pipeline.

Input notes

The tool accepts any JavaScript code. It wraps the input in script tags to leverage the html-minifier library's JS minification capabilities, then strips the wrapper tags from the output. Single-line and multi-line comments are removed.

Example

Formatted JavaScript is compressed by removing whitespace and comments:

--- Input (formatted) ---
// Greeting function
function greet(name) {
  if (name) {
    console.log("Hello, " + name + "!");
  } else {
    console.log("Hello!");
  }
}

--- Output (minified) ---
function greet(name){if(name){console.log("Hello, "+name+"!")}else{console.log("Hello!")}}