135

What JavaScript minifier do you recommend?

2

9 Answers 9

114

UglifyJS2, used by the jQuery project.

6
  • 17
    You can use UglifyJS online without the need to install it - jscompress.com . +1 for the product used by jQuery
    – Tomas
    Oct 27, 2013 at 14:13
  • 1
    is it used more than closure?
    – FutuToad
    Apr 25, 2014 at 16:25
  • @FutuToad: Current version is UglifyJS2. I was looking for a comparison of the minifiers and I found the stats here 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, 2014 at 11:56
  • PS: You can try Minify JS that is based on UglifyJS2 and your source codes won't be sent to a remote server. ;)
    – MartyIX
    Nov 29, 2014 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, 2017 at 6:47
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.

1
  • 2
    Google CC simple mode also achieves smaller size than YUI, and it's safe as well
    – gblazex
    Aug 19, 2010 at 9:57
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.

0
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.

9

There are several you can use/try:

2
7

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

1
  • 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. Jun 26, 2014 at 1:25
5

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

4

This tool: jscompressor.com is pretty good.

2
  • The website is offline. Aug 31, 2017 at 11:47
  • Thank you. It's work with me. This is the best website I have ever used for minify Javascript
    – Bao Nam
    Apr 30, 2020 at 15:32
2

YUI minifier

Not the answer you're looking for? Browse other questions tagged or ask your own question.