# JavaScript Minifier

> Quick JS minifier that strips comments and collapses whitespace. Best for trusted, simple code snippets.

URL: https://uttir.com/js-minifier
Categories: developer-tools, web-tools
Privacy: Your JavaScript is processed locally and never sent over the network.

## About

A lightweight JavaScript minifier that strips block and line comments and collapses whitespace. Useful for one-off scripts, bookmarklets, and snippets where you want a quick size reduction without setting up a build pipeline.

CAUTION: This is a syntactic minifier, not a real parser. It does not understand strings, template literals, or regular expressions, so it can mangle code that contains // or /* * / inside those constructs. For production code, use Terser, esbuild, or SWC.

## How to use

1. **Paste your JS** — A snippet, a function, or a small module.
2. **Read the minified output** — Comments and excess whitespace are stripped.
3. **Copy** — Grab the result for use elsewhere.

## Examples

### Comment stripping

Block and line comments go away.

Input:

```
/* greet */ const greet = (name) => {
  console.log("hi", name); // say hi
};
```

Output:

```
const greet = (name) => { console.log("hi", name); };
```

### Whitespace collapse

Multiple spaces and newlines become one.

Input:

```
const    a  =   1;
```

Output:

```
const a = 1;
```

## FAQ

### Why is this not as good as Terser?

Terser parses the JavaScript into an AST, which means it can safely rename variables, remove dead code, and respect string/regex literals. This tool does only the safe syntactic passes. It is great for quick wins on small snippets; it is not a replacement for a real minifier on a real codebase.

### Is it safe to use on production code?

Only if your code is simple and does not contain `//` inside strings, template literals, or regular expressions. When in doubt, test the minified output and prefer a real AST-based minifier for production.

### Will minification break my JavaScript?

No, for syntactically valid code. The minifier only renames local variables, removes whitespace, and shortens property accesses. It does not change behavior. Always test the minified output.

## Related tools

- [HTML Minifier](https://uttir.com/html-minifier) — Shrink HTML by stripping comments and collapsing whitespace. See byte savings in real time.
- [CSS Minifier](https://uttir.com/css-minifier) — Shrink CSS by stripping comments, collapsing whitespace, and tightening punctuation. See byte savings live.
- [JSON Formatter](https://uttir.com/json-formatter) — Format, beautify, and validate JSON with adjustable indentation — instantly in your browser.

---

For the full HTML page with the live tool, visit https://uttir.com/js-minifier.
This file is the markdown rendering at https://uttir.com/js-minifier.md. See https://uttir.com/llms.txt for a site-wide summary.
