What JavaScript minifier do you recommend?
-
2Have you tried http://dean.edwards.name/packer/? – Alexander Suraphel Feb 23 '15 at 07:15
-
1Although the question is old and closed, as of 2019 - terser (https://github.com/terser-js/terser) is a fairy good minifier. There's also a plugin for Rollup which is great for minifying bundles on the fly. – Levi Roberts Mar 05 '19 at 21:09
9 Answers
UglifyJS2, used by the jQuery project.

- 30,436
- 41
- 178
- 315

- 1,156
- 1
- 7
- 2
-
17You can use UglifyJS online without the need to install it - http://jscompress.com/ . +1 for the product used by jQuery – Tomas Oct 27 '13 at 14:13
-
1
-
@FutuToad: Current version is [UglifyJS2](https://github.com/mishoo/UglifyJS2). I was looking for a comparison of the minifiers and I found the stats here http://lisperator.net/uglifyjs/ - it seems that Google Closure is slower than UglifyJS. However, Closure can minify AngularJS projects. So there is no clear winner. My guess is (after an hour long research) that UglifyJS2 is used more than GC. – MartyIX Nov 29 '14 at 11:56
-
PS: You can try [Minify JS](http://js-minify.online-domain-tools.com/run/?inputType=text&beautify=0&mangle=1&mangleReservedWords=myLastName&text=var+hello+%3D+function%28myFirstName%2C+myLastName%29+%7B%0D%0A++alert%28%22Hello+%22+%2B+myFirstName+%2B+%27+%27+%2B+myLastName%29%3B%0D%0A%7D%3B%0D%0Ahello%28%22John%22%2C+%22Smith%22%29%3B) that is based on UglifyJS2 and your source codes won't be sent to a remote server. ;) – MartyIX Nov 29 '14 at 12:02
-
Does UglifyJS support es6? all tools I've found throw's errors since I use a lot of es6 functionality in my files. – kinger6621 Apr 16 '17 at 06:47
-
@MartinVseticka It seemed to have minified my code to a smaller size than closure compiler did, on top of that, it had more readability and kept whitespace. Thanks for showing me Minify JS. – brandito Jul 19 '18 at 00:22
Active
Deprecated
Google Closure Compiler generally achieves smaller files than YUI Compressor, particularly if you use the advanced mode, which looks worryingly meddlesome to me but has worked well on the one project I've used it on:
Several big projects use UglifyJS, and I've been very impressed with it since switching.

- 30,436
- 41
- 178
- 315

- 318,141
- 75
- 454
- 536
-
2Google CC simple mode also achieves smaller size than YUI, and it's safe as well – gblazex Aug 19 '10 at 09:57
JavaScript Minifier gives a good API you can use programatically:
curl -X POST -s --data-urlencode 'input=$(function() { alert("Hello, World!"); });' http://javascript-minifier.com/raw
Or by uploading a file and redirecting to a new file:
curl -X POST -s --data-urlencode 'input@ready.js' http://javascript-minifier.com/raw > ready.min.js
Hope that helps.
If you are using PHP you might also want to take a look at minify which can minify and combine JavaScript files. The integration is pretty easy and can be done by defined groups of files or an easy query string. Minified files are also cached to reduce the server load and you can add expire headers through minify.

- 9,302
- 3
- 31
- 65
There are several you can use/try:
- YUI compressor
- jsmin
- Microsoft Ajax minifier (has hypercrunching)

- 16,343
- 8
- 39
- 61
-
1What is hypercrunching? This is what I got on the subject: https://ajaxmin.codeplex.com/discussions/260683 – Ehtesh Choudhury Nov 08 '14 at 02:05
-
1@EhteshChoudhury It means that the minifier gets even more aggressive about it. It takes out unused code and shortens also the names of local variables. – Kris van der Mast Dec 17 '14 at 12:29
Pretty Diff - http://prettydiff.com/?m=minify

- 1,097
- 7
- 8
-
1I gotta say that this is by far the best online tool as some of the others crap out when you give them anything over 8000 lines to minify. – Mr. Concolato Jun 26 '14 at 01:25
This tool: jscompressor.com is pretty good.

- 3,225
- 5
- 11
- 35

- 49
- 1
-
-
Thank you. It's work with me. This is the best website I have ever used for minify Javascript – Bao Nam Apr 30 '20 at 15:32