Minifying a script
Paste the code
A snippet, a small file or the script block from a page. The presets load a small function, an event handler and an object literal.
Read the output
The minified code appears straight away. Line breaks are kept where removing them could change how the code runs, such as between statements without semicolons.
Check the saving
Under the output you see the size before and after in bytes, with the percentage.
Copy or download
Copy the code or download it as script.min.js.
Example: an opening hours banner for a shop website
A fictional garden centre shows Open now or Closed on its homepage with a small script. Minified, the comments disappear and the spaces around operators go, taking the script from 238 bytes to 172 bytes. The two statements stay on separate lines, because the second one starts on a new line in the original and the minifier does not risk joining them.
// Opening hours banner
function isOpen(hour) {
const open = 9, close = 17; // weekday hours
return hour >= open && hour < close;
}
document.getElementById('status').textContent = isOpen(new Date().getHours()) ? 'Open now' : 'Closed';function isOpen(hour){const open=9,close=17;return hour>=open&&hour<close;}
document.getElementById('status').textContent=isOpen(new Date().getHours())?'Open now':'Closed';
238 bytes to 172 bytes (27.7% smaller)When a small business site benefits
Most small sites run a handful of hand-written scripts: a cookie notice, a booking button, a review carousel, a tracking snippet from an advertising platform. Each one is small, but they are often pasted into a page builder's code box, where comments and indentation are sent to every visitor. Minifying them is a quick tidy-up before launch.
Keep the original, commented version somewhere safe. Minified code is awkward to edit, and the comments are usually the only explanation of why the script does what it does.
Questions people ask
Is minified JavaScript faster?
It is smaller, so it downloads slightly faster, and a little less text has to be read by the browser. For small scripts the difference is modest, particularly on servers that already compress files. The bigger gains come from loading fewer scripts, loading them later, and removing third-party code you no longer use.
Will minifying break my code?
It is designed not to: strings, template literals and regular expressions are copied as they are, and line breaks are kept where JavaScript might need them. It does not check syntax, though, so code that was already broken stays broken. Test the minified version on a staging page before replacing the original.
Can it shorten variable names?
No. Renaming variables safely needs a full understanding of the program's scope, which is what dedicated build tools do. This page keeps every name as written, which makes the output easier to read and debug and is the safer choice for code pasted into a website.
Can I minify JSON with this tool?
JSON is valid JavaScript, so it will work, but the JSON formatter is better suited: it validates the data, can minify or pretty-print it and points to the exact place an error occurs.
Where your data goes
The script is minified on this page in your browser. Your code is not uploaded to Map Extract or anywhere else.
Checked against the tool on