Personally I thought the same in the start, For some reason building a plugin for bubble made me feel as if bubble held the responsibility for the potential issues around what may happen if two developers products clash. Its not the way it works when your building out a full lib or some speccy new SDK or self hosted self scripted server instances with your own set of plugin builders because you build with compatibility in mind at scale.
Im not saying I have the answers to the perfect recipe & im certainly not saying this a standard of sorts but the way I go about this issue is fairly simple. I assume that each external is there already and rather than doubt it or double it, I start each need for an external lib with the old crash then bash theory…
In the case I will show the google object that exists globally when you start playing with maps, autocomplete, places, bulk geo coding and so on, this is what I have done to make sure that my code wont cause any issue.
function allClearLetsGo(){
// your googlie bits go here.
// eg. var googlieBit = new google.maps.places.Autocomplete([ELE, TYPES & RESTRICTIONS]);
// and on you go...
};
try {
if (typeof google !== 'undefined'){ // if global google object isnt undefined
allClearLetsGo(); // then run our function because we are good to go
}else{ // BUT if it is undefined, append the script to the head, this will cause it to load.
var key = 'MY-GOOGLE-API-KEY';
$('head').append('<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=' + key + '&libraries=places&callback=allClearLetsGo"></script>');
// We use the same all clear function in the scripts callback param so once its loaded it then fires our code.
}
} catch (bugger) { // and if it all goes pair shaped we spit the error out in the console & hope its not our issue to sort out..
console.log(bugger);
};
The google object I have left so broad is for a reason, its to show you can go about this fairly open or really specific depending on your needs.
Eg. we want to create the Autocomplete, so
if (typeof google.maps !== 'undefined'){
// your all clear code..
}
is a more specific check that the object google does in fact have the maps lib loaded, and meaning,
if (typeof google.maps.places !== 'undefined'){
// your all clear code..
}
is an even more specific check to see if the lib you need exists…
I have done more than enough now using the google object to vouch for this as pretty well fool proof… and if everyone went about something like this then who ever loads the lib first will be the only one that will need to…
hope this helps you guys out a bit.