0 Favourites

remote src in <script> for Firebase plugin

  • 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; cdn.firebase.com/v0/firebase-simple-login.js%22

    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.

  • 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)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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.

  • 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.

    Why is this not an option?

    You can load it asynchronously, then have an 'Is Firebase Ready' event triggered by a callback.

    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
    }
    

    Bear in mind this won't work on CocoonJS. Look at my Flurry plugin for a solution to that.

  • EDIT:

    deleted

    OK I will do async.

  • 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! lol

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
1,068 148,618
Reflextions's avatar
Reflextions
Unread hot topic
0 Favourites
[plugin] firebase
687 65,106
cybertron7's avatar
cybertron7
Unread hot topic
0 Favourites
[PLUGIN] Canvas
627 186,635
zenox98's avatar
zenox98