Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use the YUI Compressor or the new Google Closure compiler to compress my JavaScript?

YUI Compressor was the consensus best tool for minimizing, but Closure seems like it could be better.

like image 516
Josh Gibson Avatar asked Nov 06 '09 09:11

Josh Gibson


People also ask

What is closure Google what is closure in JavaScript?

What is the Closure Compiler? The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left.

What is the function of a closure compiler?

Explanation: The Closure Compiler is a tool for making JavaScript download and runs faster. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.


2 Answers

"Whichever you find best for you" I think is the general answer at the moment - YUI has been available longer so undoubtedly will be the one which currently has the consensus as being the best tool. Whereas Closure is new to us - so there isn't the wealth of experience with Closure as there is with YUI. Hence I don't think you'd find a compelling real-world arguments of why to use Closure based on people's experiences with it simply because it's new.

That's not to say you shouldn't use Closure....just my round about way of saying, I don't think there's an answer available to this until a number of people have used the 2 and compared them.

Edit: There are a couple of early comparisons, saying Closure does give an improvement: http://blog.feedly.com/2009/11/06/google-closure-vs-yui-min/
http://news.ycombinator.com/item?id=924426

Further Edit: Worth keeping an eye on issue list for Closure: http://code.google.com/p/closure-compiler/issues/list

like image 94
AdaTheDev Avatar answered Sep 28 '22 05:09

AdaTheDev


From the comparisons I've seen, Closure seems to be the clear winner in terms of minimizing file size. This article uses three popular JS libraries (jQuery, Prototype, MooTools) to compare compression between YUI Compressor and Closure Compiler: http://www.bloggingdeveloper.com/post/Closure-Compiler-vs-YUI-Compressor-Comparing-the-Javascript-Compression-Tools.aspx

Closure comes out in front in each test, particularly in its advanced mode, where it "minimizes code size about 20-25% more than YUI Compressor by providing nearly 60% compression."

like image 39
Michael Avatar answered Sep 28 '22 05:09

Michael