How to minify JavaScript online, free and without uploading
To minify JavaScript, paste your code into the JavaScript Input box, or click Choose File to open a .js, .mjs, .cjs or .jsx file. The Minified Output box fills in about 0.15 seconds after you stop typing, and Original Size, Minified Size, Saved and Reduction appear above the boxes in KB and in exact bytes. Click Copy Minified, or Download .js to save script.min.js. The built-in sample drops from 1,347 bytes to 853 bytes, which is 36.7% smaller. The minifier removes comments and whitespace only, so variables are not renamed and the code is not rewritten.
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). That includes files opened with Choose File, which are read on your device. There is no account and nothing to install, and the tool sets no size limit beyond what your browser can hold.
JavaScript minification removes the comments, spaces, tabs and line breaks that people need and the engine does not, so the file is smaller to download. This is a lighter pass than the full minifiers in build tools such as terser or esbuild, which also shorten variable names. It suits a small script, a page-builder snippet, or a quick check of how much of a file is only formatting.
To read minified code again, use the JavaScript beautifier. Other formats shrink the same way with the CSS minifier, the HTML minifier, the JSON minifier and the SQL minifier.
Table of Use: what changes and what is left alone
| In your code | Minified output | Why |
|---|---|---|
// note
/* note */ | Removed | Ordinary comments are dropped |
/*! (c) Me */, //! tag, @license, @preserve | Kept | Preserve license comments is ticked by default; untick it to remove these too |
const a = 1; | const a=1; | Spaces, tabs, indentation and blank lines go wherever JavaScript does not need them |
x + +"3" | x+ +"3" | The space stays, because x++ would mean something else |
const a = {x: 1}
const b = 2 | const a={x:1}
const b=2 | The line break between statements without semicolons is kept |
function f() {
return
1
} | function f(){return
1} | A line break after return, throw, break, continue or yield is kept, since removing it changes the meaning |
'a // b', /[/*]x y/g, `a ${b}` | 'a // b',/[/*]x y/g,`a ${b}` | Strings, regular expressions and template literals are copied exactly, spaces included; only the spaces between them go |
<div className="a"> JSX </div> | Unchanged | JSX is kept as written, including the spaces and line breaks inside it |
#!/usr/bin/env node | Kept | A hashbang stays on its own first line |
let longVariableName | let longVariableName | Names are never shortened and code is never rewritten |
If a regular expression in your code behaves oddly after a change, check it in the regex tester.
Features
- Paste, type or open a file. Choose File accepts .js, .mjs, .cjs and .jsx and shows a note such as Loaded sample-lib.min.js (86 B) from your device. Output updates as you type, and Minify runs it again.
- Size statistics. Original Size, Minified Size, Saved and Reduction are shown in B, KB or MB and in exact UTF-8 bytes. If the result is larger, which can happen with a source map comment, the boxes change to Added and Increase.
- Preserve license comments. One checkbox keeps comments that start with
/*!or//!or contain@licenseor@preserve. The sample keeps its licence line for 853 bytes, or shrinks to 813 bytes without it. - Source maps. Tick Generate source map (.map file) to add a version 3 map. Download .js and Download Source Map save
script.min.jsandscript.min.js.map, or take the name from the file you opened. The map embeds your original source. - Careful with meaning. The code is split into tokens first. Strings, template literals, regular expressions and JSX are never edited, and a space is kept wherever removing it would join two tokens.
- Safe for code without semicolons. A line break that could end a statement is kept, so the output still runs. The cost is that the result is not always a single line.
- Copy, download, clear. If the browser blocks the clipboard, a message asks you to copy the output yourself.
How to use the JavaScript minifier
- Paste your code into the JavaScript Input box, or click Choose File under Open a JavaScript File. Click Clear first to empty the sample.
- Under Minification Options, leave Preserve license comments ticked to keep licence lines, or untick it to remove every comment.
- Tick Generate source map (.map file) only if you want debugging support in browser DevTools.
- Read the result in Minified Output and check Original Size, Minified Size, Saved and Reduction above the boxes.
- Click Copy Minified to copy the code, or Download .js to save
script.min.js. If you made a map, click Download Source Map and keep both files in one folder.
Who can use it
- Front-end developers who want a minified copy of a script without setting up a bundler.
- Site owners adding a small script to a theme or page builder, who can try the page first in the HTML previewer.
- Library authors who must keep a licence line in the shipped file, using Preserve license comments.
- TypeScript users who first compile with the TypeScript to JavaScript converter and then minify the output.
- Students who want to see how much of a file is formatting, and who can compare the two versions in the text diff tool.
FAQs
How do I minify JavaScript online?
Paste your code into the JavaScript Input box, or click Choose File and open a .js, .mjs, .cjs or .jsx file. The Minified Output box fills in about 0.15 seconds after you stop typing, with Original Size, Minified Size, Saved and Reduction shown above the boxes. Click Copy Minified to copy it, or Download .js to save it as script.min.js.
Will minifying break my JavaScript?
It is built not to. Only comments and spare whitespace are removed. Strings, template literals, regular expressions and JSX are copied as written, and a line break that could be ending a statement is kept, so code without semicolons still runs. Spaces that matter, as in x + +y, stay. Test the minified file before you deploy it, as you would with any build step.
How much smaller will my JavaScript get?
It depends on how many comments and how much indentation the file has, and the Saved and Reduction boxes show the exact figure. The sample on the page goes from 1,347 bytes to 853 bytes, 36.7% smaller. Code that is already minified barely shrinks. A server that sends gzip or Brotli compresses the file further on top of this.
Does it rename variables or remove unused code?
No. It removes comments and whitespace only, so variable names, functions and every statement stay as you wrote them. That keeps the result predictable but gives a smaller saving than a full minifier. A build tool such as terser or esbuild can also shorten names and rewrite code, which this tool does not do.
How do I keep a licence comment when I minify?
Leave Preserve license comments (/*! ... */, @license, @preserve) ticked, which it is by default. Comments that start with /*! or //!, or that contain @license or @preserve, are then kept and all other comments are removed. Untick the box to remove them as well; on the sample that saves a further 40 bytes.
How do I create a source map for minified JavaScript?
Tick Generate source map (.map file), then click Download .js and Download Source Map. The minified code ends with a //# sourceMappingURL comment, so save script.min.js and script.min.js.map in the same folder. The map contains your original source code in full, so publish it only if you are happy for people to read that code.
Why is my minified code not on one line?
A line break can be the thing that ends a statement when a line has no semicolon, and removing it would change or break the program. The minifier keeps those breaks, along with the break after return or throw. The built-in sample, which ends its statements with semicolons, still comes out as 8 lines, because a break after a closing } or ) is kept when the next statement starts on a new line.
Is my JavaScript uploaded to a server?
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). Pasted code and files opened with Choose File are read and minified on your own device by a script that ships with the page. Nothing is sent to ZipConvert or anyone else, so it is safe for private or unreleased code.