Referencing external scripts and Closure

0 favourites
  • 3 posts
  • I noticed that the when the Facebook plugin gets minified, the FB api calls like FB.api stay the same to avoid breaking the code that calls those functions. I tried looking in the Facebook runtime.js file but I could not see any code that would instructs Closure to avoid renaming those methods. If I copy and paste the runtime.js into closure-compiler.appspot.com/home, the resulting file does rename those functions and gives warning like the following:

    JSC_INEXISTENT_PROPERTY: Property api never defined on FB at line 308 character 0

    FB.api('/me/feed', 'POST', publish, function(response) {

    I am trying to make my copperlicht3d plugin work with minification, but Closure is renaming the CL3D.xxx functions that belong to copperlicht in my code. It renames them to something like CL3D.Ki, etc. Is there anything that I am missing?

    BTW, I did read the section of exporting symbols (https://developers.google.com/closure/compiler/docs/api-tutorial3#removal) but I did not see any symbol exporting in the Facebook plugin's runtime file.

  • On export C2 also passes <install path>\exporters\html5\c2-externs.js to Closure Compiler as a list of externs to not be renamed (see Closure Compiler's documentation on this). A few FB functions are listed there to guarantee they are not mangled by Closure Compiler.

    Third party plugins can't edit this file, so just use the alternative syntax instead: rather than using FB.foo.bar(), use window["FB"]["foo"]["bar"](). This has the same result. A few official plugins take advantage of the c2-externs.js list simply for readability (so they can be written the first way and still not be renamed).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you Ashley!

    That explains why the Facebook API calls did not get mingled.

    I will go ahead and declare the externs in my plugin runtime.js file.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)