Skip to content

JavaScript Minifier & Beautifier

Minify JavaScript by stripping comments and whitespace, or beautify it with 2-space, 4-space or tab indentation, and see the size saved.

JavaScript Minifier & Beautifier

Minified: 1.9 KB to 1.6 KB

Input:1.9 KB
Output:1.6 KB
Saved:-16.5%
Lines:90 → 55
1,951 bytes / 90 lines
Minified output1,630 bytes / 55 lines
class Router{constructor(){this.routes=[];this.middleware=[]}use(fn){this.middleware.push(fn);return this}get(path,...handlers){this.routes.push({method:"GET",path,handlers});return this}post(path,...handlers){this.routes.push({method:"POST",path,handlers});return this} match(method,url){const params={};for(const route of this.routes){if(route.method!==method)continue;const pattern=route.path.replace(/\/g, "\\/")
        .replace(/:([\w]+)/g, (_, key) => {
          return `(?<${key}>[^/]+)`;
        });

      const regex = new RegExp(`^${pattern}$`);
      const match = url.match(regex);

      if (match) {
        Object.assign(params, match.groups);
        return { route, params };
      }
    }
    return null;
  }

  async handle(req, res) {
    // Run middleware first
    for (const mw of this.middleware) {
      await mw(req, res);
      if (res.finished) return;
    }

    const result = this.match(req.method, req.url);
    if (!result) {
      res.status(404).json({ error: "Not Found" });
      return;
    }

    req.params = result.params;
    for (const handler of result.route.handlers) {
      await handler(req, res);
      if (res.finished) return;
    }
  }
}

const router = new Router();

router.use((req, res) => {
  req.startTime = Date.now();
  console.log(`[${req.method}] ${req.url}`);
});

router.get("/api/users/:id", (req, res) => {
  const { id } = req.params;
  res.json({ id, name: "Alice", email: "alice@example.com" });
});

router.post("/api/users", (req, res) => {
  const user = { ...req.body, id: crypto.randomUUID() };
  res.status(201).json(user);
});

export default router;

Updated . Provided as is. Check the output before you rely on it in production.

How to use JavaScript Minifier & Beautifier

  1. 1

    Paste JavaScript code

    Paste ES5 or modern JavaScript into the input panel, or load the sample.

  2. 2

    Choose Minify or Beautify

    Minify removes whitespace and comments. Beautify reformats compressed code with consistent indentation.

  3. 3

    Set indentation

    Choose the indent width Beautify uses.

  4. 4

    Compare and copy

    Check the line count and size before and after, then copy or download the output.

Questions and answers

What is JavaScript Minifier & Beautifier?
Minification shrinks JavaScript by removing characters the engine does not need, such as comments and whitespace; beautifying re-indents compact code. This tool does both with a tokenizer that keeps strings and regex literals intact, without renaming variables, and reports the bytes saved.
Does JavaScript Minifier & Beautifier store or send my data?
No. All processing happens entirely in your browser. Your JavaScript code never leaves your device — nothing is sent to any server.
How much can JavaScript minification reduce file size?
Minification typically reduces JavaScript file size by 30-60% by removing whitespace, comments, and unnecessary characters. For even greater savings, use a bundler with tree-shaking and gzip compression in production.
For AI agents: how to call this tool

Machine-readable contract, endpoints and examples. Humans can ignore this section.

Best Path For Builders

Browser workflow

Runs instantly in the browser with private local processing and copy/export-ready output.

Browser Workflow

This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.

/js-minifier/

For automation planning, fetch the canonical contract at /api/tool/js-minifier.json.