开发者

Is it possible to use Closure Compiler ADVANCED_OPTIMIZATIONS with jQuery?

开发者 https://www.devze.com 2023-01-21 17:21 出处:网络
I keep getting errors that the function (renamed) does not exist for the given object. Is there a releas开发者_运维百科e or setting or something to make it work?You must use an externs file for jQuery

I keep getting errors that the function (renamed) does not exist for the given object. Is there a releas开发者_运维百科e or setting or something to make it work?


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号