Skip to content

Minify JavaScript

The same kind of minifier build tools use, running inside this page. Modern syntax and modules are understood, and your source is never stored.

  • Never stored
  • No queue, no waiting
  • No signup, no watermark
Minified

The minified JavaScript appears here.

How it works

1

Paste your JavaScript

Or drop the file in. Modules, classes and modern syntax are all understood.

2

Choose the options

Rename local variables, drop console calls, keep licence comments — each is a switch.

3

Copy or download

With the before and after size.

Renaming, removing, and what must never be touched

Three things happen, in increasing order of how much they save and how much they cost you. Whitespace and comments go, which is free. Dead code goes — a branch that can never run, a variable assigned and never read. And local names are shortened, so a carefully named calculateMonthlyTotal becomes a single letter. That last one is where most of the saving lives and it is also what makes the output unreadable, which is fine for shipping and useless for debugging.

What cannot be renamed is anything the outside world refers to by name, and getting this wrong is how minifiers break code. Exported functions, object properties accessed as strings, anything reached through window, and names used in eval all have to survive intact, because something elsewhere is looking them up by the name you wrote. Properties in particular are left alone by default: renaming user.emailAddress would break the moment that object is serialised to JSON or read by code that was minified separately.

Keep a source map or the original. Once names are gone, a stack trace from a real user reads as an error in function t at character 48,213, which tells you nothing at all. A source map restores the original names and line numbers in the debugger and in error reporting, and generating one costs nothing because it ships as a separate file that only loads when somebody opens the developer tools.

Licence comments are kept by default, and that is a legal position rather than a preference. A great deal of open-source code is permissively licensed on the single condition that its copyright notice travels with it — MIT and BSD both say so explicitly. Stripping those comments from a bundle containing third-party code puts you in breach of the licence that let you use it. They are a few hundred bytes.

When you want something else

This belongs in a build rather than in a browser tab, and modern bundlers do it as a matter of course. esbuild --minify and Rollup or Vite minify on build, generate source maps automatically, and — far more importantly — perform tree shaking, dropping the exports of your dependencies that you never import. On a real application that saves vastly more than minifying a finished file ever can.

Before optimising, measure. A bundle analyser will usually reveal that one large dependency accounts for most of the file — a date library, an icon set, a charting package pulled in whole for one chart. Replacing or lazily loading that beats any amount of minification, and code splitting so that a page only loads what it needs beats both.

Frequently asked questions

Is my code stored anywhere?

No, and for source code that is the point. Nothing is stored and no server ever sees it. Pasting proprietary source into an online minifier that posts it somewhere is a disclosure, whatever the site says about retention — and it is exactly the sort of thing that is done in a hurry without thinking.

Is this the same as the minifier in my build tool?

Almost certainly, yes. This is the same kind of minifier webpack, Rollup, Vite and most other bundlers use. The difference is only that it runs here, rather than as something you install.

Will it change what my code does?

It should not, and that is checked rather than assumed: our tests minify a module, import both the original and the minified version, run them, and compare the results. What DOES change: local variable names (unless you turn that off), constant expressions that can be worked out in advance, and dead code. Anything depending on a function's name at runtime, or on Function.prototype.toString, can break under mangling — turn mangling off if you rely on either.

What does "Module" mean?

Whether your code is parsed as an ES module or as a plain script. Modules can use import and export and are always in strict mode. It is on by default because that is what most modern code is; if your file is an old-style script that uses "with" or relies on non-strict behaviour, turn it off.

Should I drop console calls?

For production, usually yes — they are noise, and they can leak internal detail to anyone who opens the developer tools. It is off by default because silently deleting code is not something a tool should do without being asked.

Does it keep licence comments?

Yes, by default. Comments beginning /*! and comments containing @license or @preserve are kept, because stripping them from someone else's MIT-licensed library is a licence violation. Ordinary comments are removed.

Can it produce a source map?

Not on this page. A source map is only useful next to the original file at a known URL, which does not fit a paste-and-copy tool — your build tool is the right place for that.

Is there a size limit?

No fixed one. A few thousand lines minify in well under a second; a very large bundled file takes longer because the whole thing is parsed before anything is renamed. If you are minifying an entire production bundle, your build tool is the better place for it — this page is for a single file or a quick check.

Good to know: Renaming local variables makes the file smaller and the output unreadable, which is fine for shipping and useless for debugging — keep a source map or the original. Licence comments are kept by default because removing them can breach the licence of code you are allowed to use.

Put this tool on your website

Free for any blog, class page or help article. Paste one snippet and your visitors can use it right on your page.