Toolsky

Free Online Tools & Utilities for Every Task.

JS Minifier

Minify your JS code for size reduction.

Every byte of JavaScript you ship is a byte your visitors download, parse and wait on — and development code is full of bytes that exist only for humans: indentation, line breaks, explanatory comments, long descriptive names. A JS minifier strips exactly those. It rewrites your script without the whitespace, comments and (where safe) name length that readability requires, producing a file that does the identical job at a fraction of the size. This JS minifier performs that pass on code you paste in: formatted source in, compact production script out.

What Minification Actually Removes

Minification works in layers. First, comments disappear entirely — the browser never needed them. Second, unnecessary whitespace goes: newlines, indentation and repeated spaces collapse. Third, where the tool can do so safely, local variable and function names are shortened to single letters, because the runtime does not care whether a variable is called customerInvoiceTotal or a. More advanced passes fold constants and simplify expressions, though the classic three layers deliver most of the benefit.

What minification is not: it is not compression in the gzip sense (the two stack — servers should still gzip or Brotli the minified file for transfer), and it is not obfuscation. Minified code is shorter, not secret; anyone can read it with effort, a distinction the FAQ below returns to.

Why Bother Minifying?

  • Faster downloads: smaller scripts arrive sooner, which matters most on mobile connections and large applications.
  • Faster parsing: browsers parse what they receive; fewer characters means less work before execution starts.
  • Lower bandwidth bills: savings multiply across every visitor and every page view, which adds up on busy sites.
  • Better performance metrics: script weight feeds directly into loading metrics that site owners monitor for search and user experience.
  • Clean production habit: keeping readable source in your project and minified output on the server is the standard, reversible workflow.

How to Use the JS Minifier

  1. Copy the JavaScript you want to minify from your project — the readable, development version.
  2. Paste the code into the input area.
  3. Run the minify action to generate the compact version.
  4. Check the output and the size comparison if one is shown: the minified text should be dramatically shorter while remaining syntactically complete.
  5. Save the minified code into your production file (conventionally named with .min.js), keeping the original source untouched in your project.
  6. Test the page that uses the minified file. If something breaks, the unminified original is your reference and your rollback.

A Small Example With Exact Numbers

Consider this short function as written for humans:

// add two numbers
function add(a, b) {
    return a + b;
}

That snippet is 59 characters. Minified, it becomes function add(a,b){return a+b} — 29 characters, less than half, with the comment, the spaces after commas, the indentation and the optional spacing around the plus sign all gone, and the behaviour completely unchanged. Real files scale the effect up: comment-heavy, generously spaced application code routinely sheds a third or more of its size. When the deployment pipeline also serves the file through gzip compression, transfer size drops again on top of the minified size. And when you later need to read that production file during an incident, a JS formatter restores its layout — though never its original names — while a matching pass over your stylesheets with a CSS minifier keeps the whole front end on the same diet.

Tips, Limitations and Common Mistakes

  • Never edit the minified file directly. It is a build artefact. Make changes in the readable source and re-minify; editing minified output is how inconsistencies are born.
  • Minification is not security. Shortened names slow a reader down slightly but hide nothing. Never place secrets, keys or proprietary logic you truly need protected in client-side JavaScript, minified or not.
  • Watch out for code that depends on its own text. Rare patterns — functions that read their own source, or code relying on specific formatting — can break under aggressive rewriting. Test after minifying, especially older or unusual scripts.
  • Keep source maps in real projects. When debugging production, a source map lets browser tools show your original source instead of the minified line. A pasted one-off minification has no map, which is fine for small scripts.
  • Do not minify twice. Minifying an already-minified file gains almost nothing and multiplies the chance of a tool tripping on edge cases. Always start from the readable original.

Frequently Asked Questions

Does minified JavaScript run faster, or just download faster?

Primarily it downloads and parses faster because there is less of it. Execution speed of the running code is essentially unchanged, since the logic is identical.

Is minification the same as obfuscation?

No. Minification optimises for size and incidentally shortens names. Obfuscation optimises for making code hard to understand. They use some similar techniques but have different goals.

Can I undo minification?

Partially. A formatter restores indentation and line breaks, making minified code readable in structure, but original variable names and comments are gone permanently.

Should I minify code that uses eval or dynamic property names?

With care. Patterns where strings must match variable or property names exactly can be sensitive to renaming. Test thoroughly, and keep the unminified build available if behaviour changes.

Does minification replace gzip?

No — they stack. Minification removes redundancy from the source; gzip or Brotli then compresses what remains for transfer. Production servers should apply both.

Why do minified files use .min.js in the name?

It is a convention signalling "this is the production build". It helps developers avoid editing the artefact and lets pipelines and humans alike tell source and output apart at a glance.

Will minifying break my code?

Correctly written JavaScript minifies safely in the overwhelming majority of cases. The known risks are exotic: reliance on automatic semicolon insertion quirks, function-source introspection, or name-dependent tricks. Testing the minified build is the safeguard.

Ship the Small File, Keep the Readable One

Minification is the rare optimisation with no trade-off for visitors: same behaviour, fewer bytes, faster pages. Keep your source readable for the humans who maintain it, minify for the machines that download it, and let each audience get the version meant for them.