JS Minifier & Beautifier

Minify JavaScript by removing comments and whitespace, or beautify minified JS with indentation.

Input: 238 chars | Output: 166 chars | Saved 72 chars (30.3%)

What JavaScript minification does

Minifying JavaScript removes comments and unnecessary whitespace, and - in full-featured minifiers - renames local variables to single letters. The code behaves identically and can be dramatically smaller.

JavaScript benefits from minification more than CSS does, because identifier renaming has no CSS equivalent. A descriptive local variable name appearing fifty times becomes a single character fifty times.

Key takeaways

  • Minification strips comments and whitespace; full minifiers also rename local variables.
  • Typical savings are 30-60% before compression.
  • JavaScript is the most expensive asset on a page - it must be parsed and executed, not just painted.
  • Source maps let you debug minified code as if it were the original.
  • This tool performs safe whitespace and comment removal, not identifier renaming.

What a minifier does

OperationBeforeAfterDone here?
Remove comments// explanation(removed)Yes
Remove whitespacelet x = 1;let x=1;Yes
Collapse line breaksMultiple linesFewer linesYes
Rename local variableslet userCountlet aNo
Remove dead codeif (false) { ... }(removed)No
Inline single-use constantsconst x = 5; use(x)use(5)No
Tree shakingUnused exports(removed)No

Identifier renaming and dead code elimination require full parsing and scope analysis. Use a build-time tool such as Terser or esbuild for production.

This tool does the safe transformations only. Removing whitespace and comments cannot change behavior, provided the line breaks that end a statement stay: code written without semicolons relies on them, so a line break is kept wherever removing it could change meaning. Renaming variables and eliminating dead code require understanding scope, and a naive implementation will break code that uses eval, with, or reflection on function names. For production builds, use a real minifier in your pipeline.

Why JavaScript size matters more than other assets

A kilobyte of JavaScript is more expensive than a kilobyte of any other resource, because it is not merely downloaded - it must be parsed, compiled and executed on the main thread.

AssetDownloadParseExecuteBlocks rendering?
ImageYesDecodeNoNo
CSSYesYesNoYes
JavaScriptYesYesYesYes, unless deferred

On a mid-range phone, parsing and executing JavaScript can take several times longer than downloading it. This is why bundle size matters disproportionately on mobile.

Source maps

A source map is a file linking minified code back to the original, so browser developer tools can show you readable source, correct line numbers and original variable names while you debug production code.

  • Generate them in your build, which every modern bundler does by default.
  • Reference them with a //# sourceMappingURL= comment at the end of the file.
  • Decide deliberately whether to deploy them publicly. Public maps make debugging easy for you and also expose your original source to anyone.
  • A common compromise is uploading maps to your error tracking service without serving them from the site.
Without a source map, a production stack trace is close to useless. "TypeError at a.js:1:4823" tells you almost nothing. Error tracking services accept uploaded source maps and translate stack traces automatically, which is worth setting up before you need it rather than after.

Reducing bundle size properly

  1. Audit your dependencies. A single convenience library can outweigh all of your own code.
  2. Enable tree shaking and import only what you use, not whole namespaces.
  3. Code-split by route so a visitor downloads only what the current page needs.
  4. Lazy-load anything below the fold or behind an interaction.
  5. Prefer modern syntax and avoid shipping transpiled code with polyfills to browsers that do not need them.
  6. Minify and compress as the last step, not the first.
  7. Measure with a bundle analyzer - the largest contributors are frequently not the ones you expect.

Beautifying minified code

Beautifying restores formatting to minified JavaScript, which is useful for reading a third-party library or investigating something in production. It restores structure, not information:

  • Indentation and line breaks come back.
  • Comments do not. They were removed permanently.
  • Original variable names do not if the code was renamed - a, b, c is what you get.
  • Module structure is generally unrecoverable after bundling.
Everything runs in your browser. Your code and files are processed entirely on your own device - nothing is uploaded, logged or stored.

Frequently Asked Questions

What does minifying JavaScript do?

It removes comments and unnecessary whitespace, and in full-featured minifiers renames local variables to single characters. The code behaves identically and is typically 30 to 60 percent smaller before compression.

Does this tool rename variables?

No. It performs the safe transformations - whitespace and comment removal - which cannot change behavior. Renaming requires full scope analysis and can break code using eval or reflection. Use Terser or esbuild in your build pipeline for production.

Does minification change how my code behaves?

It should not. Whitespace and comment removal is entirely safe. More aggressive transformations such as renaming and dead code elimination are safe in almost all cases, but can break code that inspects function names or uses eval.

What is a source map?

A file linking minified code back to the original source, so browser developer tools show readable code, correct line numbers and original variable names while debugging. Without one, a production stack trace pointing to line 1 column 4823 tells you almost nothing.

Should I deploy source maps publicly?

It is a trade-off. Public maps make debugging production issues straightforward and also expose your original source to anyone who looks. A common compromise is uploading maps to your error tracking service without serving them from the site.

Why does JavaScript size matter more than image size?

Because JavaScript must be parsed, compiled and executed on the main thread, not merely downloaded and decoded. On a mid-range phone, processing can take several times longer than downloading, which is why bundle size hurts mobile performance disproportionately.

What reduces bundle size more than minification?

Auditing dependencies and code splitting. A single convenience library can outweigh all your own code, and shipping every route's JavaScript to every visitor is far more costly than any amount of whitespace. Use a bundle analyzer - the biggest contributors are rarely the expected ones.

Can I recover the original code from minified JavaScript?

Only partially. Beautifying restores indentation and line breaks, but comments are gone permanently and renamed variables stay as single letters. Module structure is generally unrecoverable after bundling.

Related Calculators