remote src in <script> for Firebase plugin

For developers using the Construct 2 Javascript SDK

Post » Tue Nov 12, 2013 11:51 pm

I want to add a remote JS library in a <script> tag in the HTML. I added the dependencies like so in the plugin properties:

"dependency": "https://cdn.firebase.com/v0/firebase.js; https://cdn.firebase.com/v0/firebase-simple-login.js"

which somewhat works (the exported HTML is correct) except that C2 installations with debugging turned on complain the dependency cannot be met (locally).

But I do not want to include the JS libraries locally, as that is the mechanism by which you get around same origin policies. It's for *very useful* database-as-a-service integration Firebase. (http://www.scirra.com/forum/plugin-firebase_topic79393.html)

Is there another way I can add my own <script> tags in the HTML. Dynamic loading of external JS is not an option (like how facebook does it), because the plugin needs the API immediately.
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Wed Nov 13, 2013 7:54 am

I'm pretty sure you can't load online dependency in the edittime.js.
You can only set local files. If you want to load your api, you just need to call it from runtime.js.

Look at the facebook plugin (at the end of onCreate)septeven2013-11-13 07:54:49
Passionate developer

If my work helped you to make your project, please consider making a donation :)
B
44
S
12
G
14
Posts: 631
Reputation: 10,987

Post » Wed Nov 13, 2013 12:25 pm

Yeah, try loading the files dynamically from script. You can then also check if you're running in preview mode and skip it if so.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Wed Nov 13, 2013 3:52 pm

[QUOTE=tlarkworthy] Is there another way I can add my own <script> tags in the HTML. Dynamic loading of external JS is not an option (like how facebook does it), because the plugin needs the API immediately. [/QUOTE]
Why is this not an option?

You can load it asynchronously, then have an 'Is Firebase Ready' event triggered by a callback.
[CODE]
var s = document.createElement("script");
s.src = "https://cdn.firebase.com/v0/firebase.js";
document.getElementsByTagName("head")[0].appendChild(s);
s.onload = function() {
     // Set a variable on the callback which determines the loaded state of remote js
}
[/CODE]
Bear in mind this won't work on CocoonJS. Look at my Flurry plugin for a solution to that.thehen2013-11-13 15:53:14
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,920

Post » Wed Nov 13, 2013 4:58 pm

EDIT:
deleted

OK I will do async.tlarkworthy2013-11-13 17:10:27
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Wed Nov 13, 2013 6:01 pm

myeah so I have done async and pushed the load flag onto a $.Deferred object.

I have wrapped my functions to wait for the loaded promise before using the library. This has the advantage of not pushing the async race conditions downstream to the user. But it is a massive pollutant to my codebase for the sake of not being able to do normal HTML 101 stuff.

I am not particularly happy with this solution. Give use remote-dependancy! It will cause less bugs in the ecosystem in the long run!

EDIT: well those pollutants were nothing compared with trying to evade the closure minification on a 3rd party asyncronously loaded library! loltlarkworthy2013-11-13 20:04:05
B
14
S
5
G
1
Posts: 60
Reputation: 1,052


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests