views:

389

answers:

4

I'm testing google closure-compiler and wanting to compile facebox Plugin with the option "Advanced" , an error occurs the function trying to find "a.H".

Has anyone tried to compile with this option jQuery plugins with a good result.

Thank you.

EDIT: Clearly this re-naming the jQuery methods, but is it possible to include jQuery and re-name all methods equally?.

A: 

When I tried the Closure compiler changed the names of the functions I accessed. So when I used (as an example) $.each(// code) the compiler changed it to $.a(// code ). I believe there is your problem.

adamse
Yes, but as you can solve that problem. Because I'm including jQuery and fails.
andres descalzo
A: 

I think you have to include all scripts within your application for it to work across all of them.

Corey Hart
+1  A: 

Yes, you would have to concatenate both jquery.js and plugin.js into one file, but at the moment some parts of jQuery doesn't compress correctly with Advanced Compilation option, but you can still use the Simple Compilation.

I'm sure jQuery team will soon release a version which can be compiled using Advanced Compilation option.

If you're interested in Advanced Compilation check out these tutorials. Once you've read em, you'll understand why some parts need changing before you'll be able to compile em using Advanced Compilation without errors.

Maiku Mori
@Maiku Mori thank you. I will follow the tutorial to see more options. I will jQuery.min used with jQuery.["Method"] to see if I compile my scripts with Advanced Compilation.
andres descalzo
+1  A: 

I encountered the same issue when trying to compress a custom JS library of jQuery Plugins. Closure (unless you give it a reason not to) will just rename any jQuery library calls from within your plugin. And worse yet it will not even warn you (how could it? it assumes you the programmer know what you are doing!) the solution is to reference the external js file (or url points to the library). I used the web tool: http://closure-compiler.appspot.com/home

by applying the fowlloing preamble, i was able to compile the file successfully:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @warning_level QUIET
// @output_file_name default.js
// @formatting pretty_print
// @externs_url http:// ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js
// @externs_url http:// ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js
// ==/ClosureCompiler==

The only issue remaining is making the compiler realize that the plugins name, cannot be simplified:

(function($) { $.fn.extend({ <name>:function(options) { } }); })(jQuery);

Because this is the name exposed to the world. Any ideas?

Ryan