Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Closure Compiler ADVANCED_OPTIMIZATIONS with jQuery?

I keep getting errors that the function (renamed) does not exist for the given object. Is there a release or setting or something to make it work?

like image 443
700 Software Avatar asked Oct 25 '10 18:10

700 Software


3 Answers

You must use an externs file for jQuery when using Closure Compiler Advanced Mode with jQuery. Extern file will tell compiler these are reserved methods and accept these argument and argument data types should be like that, so do not minify method names and check argument data types in that way.

You can get externs file which is created by Google Developers here. This file generated for jQuery-1.4.3. But currently probably will work any version of jQuery. Newly added methods may not include in that file, so you should add it to externs file, syntax and synonyms are so simple.

Also you can say location of externs file to compiler by using an extra compier flag. Syntax should be like this

--compiler_flags= "--externs=path/to/jquery.externs.js"

Also you can use this tool which is an online externs extractor for Closure Library.

like image 128
Fatih Acet Avatar answered Nov 01 '22 22:11

Fatih Acet


You have to declare jQuery as an extern to the compiler...however I'm not sure if anyone's made one, there was an extern file for 1.3.2, but I haven't seen any 1.4+ versions.

Edit: this issue thread here has the community building a 1.4 version.

like image 7
Nick Craver Avatar answered Nov 01 '22 22:11

Nick Craver


jQuery is not compatible (yet) with the Closure Compiler in advanced mode. I agree it would be a very good thing to make it compatible, because its method-chaining syntax lends very readily to prototype virtualization for much improved execution speed.

In fact, among the popular JavaScript libraries (other than Closure Library, that is), only the Dojo Toolkit is compatible with Closure Advanced mode.

http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t

like image 3
Stephen Chung Avatar answered Nov 01 '22 22:11

Stephen Chung