JavaScript Minifier and Beautifier - Terser in Your Browser

Tools /
/ Formatters / JavaScript Minifier

JavaScript minifier and beautifier

Shortening local names saves the most bytes, but it breaks code that looks names up as text - inside eval, new Function, or a framework that reads parameter names. Turn it off if you rely on any of those.

What this tool does

Minifying JavaScript is not stripping spaces. Doing it by search-and-replace produces files that look fine and behave differently, and the difference shows up in production. This page runs Terser - the same engine behind the build step of most projects - inside your browser.

How to use it

  1. 1 Paste the JavaScript into the box.
  2. 2 Choose a target and decide whether to shorten names.
  3. 3 Press Minify - or Beautify to open a minified file back up.

Why a parser and not search-and-replace

JavaScript inserts semicolons where you left them out. Remove the newline between "return" and its value and the function starts returning undefined - the file is still valid, it just does something else. The same character means division in one place and a regular expression in another. Telling these apart needs the grammar, not a pattern, which is why this page uses a real parser.

What actually gets smaller

Whitespace and comments are the smallest part of it. The real savings come from renaming local variables to single letters, merging separate declarations into one, folding constants, and dropping code that can never run. Those are all tree operations - the minifier has to know that two names refer to the same binding, and that nothing between them reads it.

Where shortening names bites

A minifier can rename what it can see. It cannot see a name written as text: eval("count + 1"), new Function("a", "return a"), or a framework that reads a function's parameter names to decide what to inject. Those keep looking for the old name and find nothing. This is a property of the language, not a flaw in the tool - which is why the switch is yours to make rather than something applied silently.

Beautify is not the original file back

Beautify restores indentation and line breaks, so a minified file becomes readable again. It cannot restore what was thrown away: comments are gone, and if names were shortened they stay short - no tool can guess that "e" was once "errorMessage". For debugging a production file, a source map is the only thing that brings the original back.

JavaScript minification - frequently asked questions

Terser - the successor to UglifyJS and the default minifier in webpack, Rollup and Vite. It is the same engine your build step already runs, which means the output here matches what you would get from a build, not an approximation of it.
New
SQL Formatter Break a long query onto readable lines, or squeeze it back onto one. Keeps your keyword casing, your quoted names and your strings exactly as written.
Popular Today
HTML Formatter Indent messy HTML so you can read it, or strip it down so it ships smaller. Works on fragments too, and never rewrites your markup into something else.

Related Dev Tools

JSON Formatter Format, minify and validate JSON in your browser. Broken input is pinpointed by line and column, and a collapsible tree shows the structure.
HTML Formatter Indent messy HTML so you can read it, or strip it down so it ships smaller. Works on fragments too, and never rewrites your markup into something else.
CSS Minifier Compress CSS by stripping comments and whitespace, or expand it back with clean indentation. Keeps calc() spacing, strings and license comments intact.
XML Formatter Indent messy XML so you can read it, or strip it down so it ships smaller. Handles RSS, CDATA and namespaces, and never rewrites your document.
SQL Formatter Break a long query onto readable lines, or squeeze it back onto one. Keeps your keyword casing, your quoted names and your strings exactly as written.

Other Tools You May Like

Word to PDF Convert Word to PDF for free: upload a DOC, DOCX, ODT or RTF file and download a properly formatted PDF in seconds - no registration or watermark.
PDF to Word Convert PDF to Word for free: upload a PDF and download an editable DOCX in seconds - no registration, no watermark and nothing to install.
Word Counter Free word counter: paste any text to count words, characters, sentences and paragraphs, and see the estimated reading time - nothing leaves your browser.
Character Counter Free character counter: count characters with and without spaces, plus words and lines, and check SEO limits for titles and meta descriptions.
Keyword Density Checker Free keyword density checker: paste text or a URL to see how often each word and phrase appears, with percentages for one, two and three-word terms.