How to wait for another JS to load to proceed operation?
<p>I have an issue. One of my JS scripts needs Facebook SDK and Twitter widgets JS to load first. Facebook creates <code>FB</code> object, Twitter creates <code>twttr</code> object. Both of them create these objects AFTER my script fires, even though they're loaded from <code>&lt;head&gt;</code>. </p>

<p>I think solution is to periodically check if FB and twttr are defined, and then proceed with executing my script. But I have no idea how to do this.</p>

<p>I tried creating a loop </p>

<pre><code>while (typeof FB === 'undefined' || typeof twttr === 'undefined' || typeof twttr.widgets === 'undefined') {
    // run timeout for 100 ms with noop inside
}
</code></pre>

<p>But this clearly does not work as it keeps firing timeouts at a high speed and page hangs.</p>

<p>Please help me, I can't sleep because of this issue.</p>
