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
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
Paste JavaScript code
Paste ES5 or modern JavaScript into the input panel, or load the sample.
- 2
Choose Minify or Beautify
Minify removes whitespace and comments. Beautify reformats compressed code with consistent indentation.
- 3
Set indentation
Choose the indent width Beautify uses.
- 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?
Does JavaScript Minifier & Beautifier store or send my data?
How much can JavaScript minification reduce file size?
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.