I am using RequireJS in ASP.NET. There is a user control that contains a script file and registers the launch of a script to initialize itself. Here is the generated code:
<script src="script/UserControls/myctrl.js" type="text/javascript"></script>
...
<script type="text/javascript"> function myCtrl1_init() { </script>
The file myctrl.js looks something like this:
require(['script/dep1', 'script/dep2'], function(dep1, dep2) { MyCtrl = function () { }; MyCtrl.init = function(id) { dep1.doSomething(); } };
Thus, the problem is that the script is run before the myctrl.js file was able to run. Currently, the call request uses a callback function, which obviously does not work until a later version, and this is the problem ... the script returns, and the browser continues to run the script before MyCtrl was created.
I tried just calling require(['script/dep1', 'script/dep2']); at the top of the file, but this does not block, and the script fails because the dependencies are not yet loaded. Dependencies are, by the way, modules. they use define() .
Is there a way to download a script file synchronously with RequireJS? The API documentation says that βUsing RequireJS in a server-side JavaScript with synchronous loading should be as simple as redefining require.load (),β but I have no idea what that means.
Any suggestions?
source share