title: How to load a script synchronously with RequireJS
body: <p>I am using RequireJS in ASP.NET. There is a user control that includes a script file, and registers a startup script in order to initialize itself. Here's the generated code:</p>
  
  <pre><code>&lt;script src="script/UserControls/myctrl.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function myCtrl1_init() {
      // initialize control
      // *JS ERROR* because myctrl.js hasn't run yet
      Sys.Application.remove_load(myCtrl1_init);
  }
  Sys.Application.add_load(myCtrl1_init);
  &lt;/script&gt;
  </code></pre>
  
  <p>The myctrl.js file looks something like this:</p>
  
  <pre><code>require(['script/dep1', 'script/dep2'], function(dep1, dep2) {      
      MyCtrl = function () {
      };
      MyCtrl.init = function(id) {
          dep1.doSomething();
      }
  };
  </code></pre>
  
  <p>So, the problem is that startup script runs before the myctrl.js file has had a chance to run. Currently, the require call uses a callback function, which obviously doesn't run until later, and this is the problem... the script returns and the browser continues to the startup script before MyCtrl has been created.</p>
  
  <p>I have tried simply calling <code>require(['script/dep1', 'script/dep2']);</code> at the top of the file, but that doesn't block either, and the script fails because the dependencies haven't loaded yet. The dependencies are modules, by the way, e.g. they use <code>define()</code>.</p>
  
  <p>Is there a way to load a script file synchronously with RequireJS? The API documentation says that "Using RequireJS in a server-side JavaScript environment that has synchronous loading should be as easy as redefining require.load()", but I have no idea what this means.</p>
  
  <p>Any suggestions?</p>