135

What JavaScript minifier do you recommend?

Timo Tijhof
  • 10,032
  • 6
  • 34
  • 48
user160820
  • 14,866
  • 22
  • 67
  • 94
  • 2
    Have you tried http://dean.edwards.name/packer/? – Alexander Suraphel Feb 23 '15 at 07:15
  • 1
    Although 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 Answers9

114

UglifyJS2, used by the jQuery project.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Andreas Hofmann
  • 1,156
  • 1
  • 7
  • 2
  • 17
    You 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
    is it used more than closure? – FutuToad Apr 25 '14 at 16:25
  • @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
33

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.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Tim Down
  • 318,141
  • 75
  • 454
  • 536
12

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.

Quill
  • 2,729
  • 1
  • 33
  • 44
chilts
  • 451
  • 3
  • 12
10

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.

2ndkauboy
  • 9,302
  • 3
  • 31
  • 65
9

There are several you can use/try:

Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61
7

Pretty Diff - http://prettydiff.com/?m=minify

austincheney
  • 1,097
  • 7
  • 8
  • 1
    I 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
5

Sometimes i use this: http://closure-compiler.appspot.com/home

Filipe Costa
  • 655
  • 3
  • 13
  • 30
4

This tool: jscompressor.com is pretty good.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
2

YUI minifier

tom
  • 8,189
  • 12
  • 51
  • 70