I am trying to figure out how to load javascript files dynamically, or
rather, what the flow is in the browser. I have a page written that
uses ajax calls to retrieve pages into a div on the page. I can't put
javascript inside these files because the browser won't read it when
its loaded. As a result I've had to put all my javascript inside
a .js file and import it via javascript when a menu is clicked. This
all works just fine, however, sometimes I have to click the menu twice
before it will load. It appears that even though it loads the script,
its not available for immediate use. The actual page that loads
afterwards is on a timer. If I set it for 3 seconds later it works
100% of the time, if I set it for 1 second about 80% of the time it
will NOT work.

Is there some way that I can detect when a script is available for use
and then load the page that requires it?