JavaScript Minifier
Paste a script to remove comments and extra whitespace. Strings, template literals and regular expressions are left untouched, and uncertain line breaks are kept.
Dieser Inhalt ist auf Englisch.
This is a basic minifier. It removes comments and spaces but keeps every name as it is, so savings are smaller than a full build tool gives. Test the result before you use it on a live site.
Durchgerechnete Beispiele
Minifying a small function
function add(a, b) { // sum return a + b; }
function add(a,b){return a+b}
The comment is dropped, and spaces are kept only where two words or symbols would otherwise run together.
Keeping text inside quotes
const msg = "Hello world";
const msg="Hello world"
Text inside quotes is copied exactly, so the three spaces in the message are preserved.
Über JavaScript Minifier
A JavaScript minifier makes a script smaller by removing the parts people need but computers do not: comments, indentation and the line breaks and spaces between statements. This tool reads your code piece by piece, so text inside quotes, template literals and regular expressions is copied exactly as written, while comments and spare whitespace are dropped. It then shows the original size, the new size and the percentage saved, so you can see how much a script has shrunk. Large scripts are handled in the same way, and the result updates as you type.
This is a basic minifier. It does not rename variables, shorten code or remove unused functions, so the saving is smaller than you would get from a full build tool. In return it changes nothing about how your code is written. JavaScript can treat a line break as the end of a statement when semicolons are missing, so line breaks are removed only where the surrounding code makes it certain, and kept otherwise. Always test the minified file before publishing it.
So verwenden Sie JavaScript Minifier
- Paste your JavaScript into the input box, or open a .js file.
- Choose whether to remove line breaks where the code allows, or keep every one.
- Decide whether to keep licence comments such as /*! notices.
- Check the size saved, then copy or download the minified script.
Typische Einsatzzwecke
- Trimming a small script before adding it to a page
- Shrinking a snippet to paste into a tag manager or a bookmarklet
- Checking how much of a file is made up of comments and indents
- Preparing a short script for a message or form with a size limit
Häufige Fragen
How do I minify JavaScript?
Paste your script into the input box. The minified version appears on the right straight away, together with the original size, the new size and the percentage saved. Copy it or download it as script.min.js, then test it where you plan to use it.
Will minifying break my code?
It should not. Strings, template literals and regular expressions are copied exactly, and spaces are kept wherever two words would otherwise join together. Line breaks that could affect where a statement ends are kept. It is still sensible to run your usual tests on the minified file.
Why are some line breaks still there?
When a script leaves out semicolons, JavaScript uses line breaks to decide where statements end. Removing one in the wrong place can change what the code does, so line breaks are only removed where the neighbouring code makes it certain. The result tells you how many were kept.
Does this rename variables or remove dead code?
No. It is a basic minifier that only removes comments and unneeded whitespace. Renaming variables and removing unused code need a full understanding of the whole program, which is the job of a build tool. Expect smaller savings here than from such tools.
What happens to licence comments?
Comments that start with /*! and those containing @license or @preserve are kept by default, because many projects require their notices to stay with the code. Untick the option if you want every comment removed from the minified result.