title: Running a global function before the other functions in all the JavaScript pages
body: <p>I have a fb.js file which is included in all the js files of my app. 
  fb.js contains an authenticating function <code>window.fbAsyncInit</code> which runs asynchronously fetching the id &amp; other details of a user from Facebook. This data is required by other functions of the page.</p>
  
  <p>The problem I am facing is </p>
  
  <p>A. Right now all the functions are running asynchronously irrespective of their occurrence. I need to run this function before the other functions of the page &amp; wait for the response before running further functions. So that I can use the response of this function in other functions.</p>
  
  <p>B. May be I don't include this authentication function in every page &amp; run just once when the app loads for the first time &amp; pass the data to other pages. Would this be achievable? I am using JQuery.</p>
  
  <p>All the functions of a page excluding <code>window.fbAsyncInit</code> are triggered within:</p>
  
  <pre><code>$(document).ready(function() {
      dummyFunction();
  });
  </code></pre>
  
  <p>Occurrence in the page </p>
  
  <pre><code>window.fbAsyncInit{}
  Other functions within $(document).ready(function() {});
  </code></pre>
  
  <p>A snippet below of the Facebook function</p>
  
  <pre><code>window.fbAsyncInit = function() {
      FB.init({
        appId      : 'xxxx',
        xfbml      : true,
        version    : 'v2.9'
      });
      FB.AppEvents.logPageView();
    }
  </code></pre>
  
  <p>Disclaimer: I don't have much experience with JavaScript. I am more of a backend developer.</p>