JavaScript beautifier

Format minified or messy JS with readable indentation in the browser.

Overview

Receiving a minified JavaScript file without the corresponding source map is one of the most frustrating moments in a developer's life. A single line of eighty thousand characters housing three hundred different functions is not code — it is a sequence of characters that the machine's interpreter understands but a human being cannot read. This happens with third-party libraries, tracking scripts, and not infrequently with a project's own code when the source map was deleted or never generated.

The beautifier reverses this process: it adds indentation, breaks long expressions across multiple lines, and restores the visual structure that the minifier discarded. It does not recover the original variable names — that is impossible without the source map — but it transforms `function a(b,c){if(b>c){return b}return c}` into something with two-space indentation and line breaks that the human eye can scan. It is not as elegant as the original, but it is functional for debugging.

Source maps are .map files that establish the correspondence between minified code and original code. When the browser finds a source map (referenced by a `//# sourceMappingURL=` comment at the end of the file), the devtools show the original code during debugging. Most modern bundlers — Vite, webpack, Rollup — generate source maps automatically in development mode. In production, however, source maps are often omitted for security (to avoid exposing original logic to the public) or for performance (they are large files). It is precisely in those cases that an online beautifier makes a real difference.

Technical deep dive

Source maps: the missing link between minified and original code

  • A source map (.map file) is a JSON that maps every position in the minified code back to the corresponding file and line in the original source. Without it, a stack trace pointing to `bundle.min.js:1:38492` tells you absolutely nothing useful.
  • The comment `//# sourceMappingURL=bundle.min.js.map` at the end of the minified file instructs the browser to load the source map. The devtools then display the original code, with real variable and function names, during the debug session.
  • In development, bundlers generate source maps automatically. Vite, webpack, and Rollup all have dedicated options: `devtool: 'source-map'` in webpack, `build.sourcemap: true` in Vite.
  • In production, source maps are commonly omitted for two reasons: security (they expose internal logic to the public) and size (a source map can be larger than the bundle itself). The alternative is to upload source maps only to an error-monitoring server like Sentry.
  • When no source map exists and the code is minified, the beautifier is the only tool available. It does not restore original variable names, but it at least makes the code structurally readable.

When a beautifier is truly indispensable

  • Third-party libraries distributed without source maps: jQuery, analytics scripts, chat widgets, tracking pixels. These files arrive minified with no documentation of internal structure.
  • Debugging production issues when source maps were removed from the deployment by company security policy. The error appears in the log, but the minified code is unreadable.
  • Security audits: when you need to understand what a third-party script actually does before including it on your site. The beautifier makes a quick read of the logic possible.
  • Legacy code without version history: old .js files where the original source was lost and only the minified version remains on the production server.
  • Version comparison: when you need to understand what changed between two minified versions of a library, a diff between beautified files is far more readable than a diff between the minified versions.

Tool guide

  • What it does Takes minified or messy JavaScript and applies readable line breaks and indentation.

  • When to use Quick debugging, snippet inspection, and review before refactoring.

Code Snippets

Generate a source map with esbuild (CLI)
# Bundle and minify with an external source map
esbuild src/app.js \
  --bundle \
  --minify \
  --sourcemap \
  --outfile=dist/app.min.js

# Output:
# dist/app.min.js         (minified bundle)
# dist/app.min.js.map     (external source map)

# The minified file will end with:
# //# sourceMappingURL=app.min.js.map

# For inline source map (not recommended for production):
esbuild src/app.js --bundle --minify --sourcemap=inline --outfile=dist/app.min.js
Generate a source map with webpack (config)
// webpack.config.js
module.exports = {
  mode: 'production',
  entry: './src/app.js',
  output: {
    filename: 'bundle.min.js',
    path: __dirname + '/dist',
  },

  // 'source-map': separate .map file (recommended for production)
  // 'eval-source-map': inline, development only
  // 'hidden-source-map': generates the .map but omits the comment
  //   (useful for Sentry without exposing maps to the public)
  devtool: 'source-map',
};

// For Vite, in vite.config.js:
// export default { build: { sourcemap: true } }

Common input

function hello(){const x=1;if(x){console.log('ok');}}

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.