JavaScript: how to create a JS event that requires 2 seperate JS files to be loaded first while down
Posted
by Teddyk
on Stack Overflow
See other posts from Stack Overflow
or by Teddyk
Published on 2010-05-10T21:32:24Z
Indexed on
2010/05/10
22:34 UTC
Read the original article
Hit count: 233
I want to perform asynchronous JavaScript downloads of two files that have dependencies attached to them.
// asynch download of jquery and gmaps
function addScript(url) {
var script = document.createElement('script');
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
addScript('http://google.com/gmaps.js');
addScript('http://jquery.com/jquery.js');
// define some function dependecies
function requiresJQuery() { ... }
function requiresGmaps() { ... }
function requiresBothJQueryGmaps() { ... }
// do some work that has no dependencies on either JQuery or Google maps
...
// QUESTION - Pseudo code below
// now call a function that requires Gmaps to be loaded
if (GmapsIsLoaded) { requiresGmaps(); }
// QUESTION - Pseudo code below
// then do something that requires both JQuery & Gmaps (or wait until they are loaded)
if (JQueryAndGmapsIsLoaded) { requiresBothJQueryGmaps(); }
Question: How can I create an event to indicate when:
- JQuery is loaded?
- Google Maps is loaded
- JQuery & Google Maps are both loaded?
© Stack Overflow or respective owner