JavaScript Minifier
Strip whitespace, comments and long local names from JavaScript, and drop console calls if you like
Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.
Did this tool do the job?
Thanks, your feedback came through.
How it works
Paste your code into the left panel and the minified version shows up on the right within a moment. The tool really parses the code, so it understands what you wrote: it removes whitespace, line breaks and comments, simplifies constructs like if (x) { return a; } else { return b; } into return x ? a : b, and deletes code that can never run, such as anything after a return. With name shortening on, local names inside a function such as total, items or shippingFee become single letters like n, t or e. Global names that other scripts might call, like the outermost function name cartTotal, are deliberately left alone so your page keeps working. To strip console.log calls before going live, set the second option to Remove. Comments starting with /*! are always kept. If the code has a syntax error, nothing is minified; instead you get the line, the column and the unexpected character. The result line shows the size before and after in bytes and the saving as a percentage.
This tool is also known as javascript minifier, minify js, js minify online, minify javascript, compress javascript, uglify js online.
What is Minify?
To minify JavaScript is to rewrite it as the shortest code that still does the same job. It happens in three steps: deleting characters nobody needs (whitespace, line breaks, comments), simplifying expressions (short conditional forms, removing code that never runs) and shortening local names. A smaller file downloads and parses faster, which brings forward the moment a page responds to taps and clicks.
What is Mangling?
Mangling replaces the names of local variables and parameters inside functions with one-letter names, so items and shippingFee become n and t. Local names are invisible outside their function, which makes this safe, and it is one of the biggest savings in minification. Global names are left alone because other scripts and onclick attributes in the HTML may use them.
Two traps when minifying
The first is global names. If a button on your page calls onclick="cartTotal()", that name must survive minification. This tool never shortens the outermost names, only the local ones inside functions, so minifying a single script file does not break the links from your HTML. If your code reaches a local variable by name through eval or a string, shortening will break it; turn name shortening off in that case.
The second is debugging. When minified code throws an error, the browser points at something like line 1, column 18342, which means nothing in your source. Always keep the unminified source and publish the minified copy. The JavaScript formatter can make minified code readable again if you need it, but shortened names do not come back.
Which setting for which job
Your own site's script: shorten names and remove console calls for the smallest result. A script you will share or debug later: keep names; the saving is a bit smaller, but error messages stay meaningful.
This tool minifies one file at a time. It does not bundle several files and does not resolve module imports. Projects built with webpack or Vite already minify during the build; this page is for single-file scripts, snippets you paste into a CMS or a WordPress plugin, and quick experiments.
Frequently asked questions
How do I minify a JavaScript file?
Paste the code into the left panel on this page. The right panel shows it without whitespace and comments and with shorter local names. Copy it or download it as a .min.js file; the result line shows how many bytes you saved.
Can minifying break my code?
For a single script it usually does not: the tool parses the code, only applies changes that keep its meaning, and never shortens global names other scripts may call. If the code reaches a local variable by name through eval or a string, name shortening breaks it; set the local names option to No. Try the minified file on your page once before publishing it.
What does "The code could not be read" mean?
There is a syntax error: a bracket or quote that is never closed, or a missing comma. The message gives the line, the column and the character that was not expected there. Fix it and paste again, and minification runs on its own.
Is my code sent anywhere?
No. The minifier runs inside your browser; your code never leaves this page and is not uploaded to any server.