What JavaScript minifier do you recommend?
-
2Have you tried dean.edwards.name/packer?– Alexander SuraphelFeb 23, 2015 at 7:15
-
1Although the question is old and closed, as of 2019 - terser (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 RobertsMar 5, 2019 at 21:09
9 Answers
UglifyJS2, used by the jQuery project.
-
17You can use UglifyJS online without the need to install it - jscompress.com . +1 for the product used by jQuery– TomasOct 27, 2013 at 14:13
-
1
-
@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.– MartyIXNov 29, 2014 at 11:56
-
-
Does UglifyJS support es6? all tools I've found throw's errors since I use a lot of es6 functionality in my files. Apr 16, 2017 at 6:47
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.
-
2Google CC simple mode also achieves smaller size than YUI, and it's safe as well– gblazexAug 19, 2010 at 9: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.
There are several you can use/try:
- YUI compressor
- jsmin
- Microsoft Ajax minifier (has hypercrunching)
-
1What is hypercrunching? This is what I got on the subject: ajaxmin.codeplex.com/discussions/260683 Nov 8, 2014 at 2: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. Dec 17, 2014 at 12:29
Pretty Diff - http://prettydiff.com/?m=minify
-
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. Jun 26, 2014 at 1:25
This tool: jscompressor.com is pretty good.
-
-
Thank you. It's work with me. This is the best website I have ever used for minify Javascript– Bao NamApr 30, 2020 at 15:32