My understanding is that it shouldn't happen, but it does. What is the most appropriate workaround for these libraries?
Notes:
- I figured running these scripts after
require.js
manually (using a script tag) should work, and indeed it seems like it does. However, the RequireJS documentation explicitly warns that thedata-main
script is run asynchronously. Whilerequire.js
should have properly defined thedefine
function needed by the scripts defining multiple named modules, I also assume that without the proper configuration loaded from thedata-main
script, bad things may happen in a non-deterministic way. Is this correct? - I also fail to see how any combination of the
shim
,map
,bundles
andpaths
configuration properties can help in this case, although I hope I'm missing it.
Clarification on the first note: (My bad, it's really not clear)
What I describe here is simply to manually execute (using an HTML script tag) the script that defines multiple modules after RequireJS and the data-main
script. With the knowledge that the latter is run async, my worries should become more obvious (but feel free to ask me to detail some more). The bulk of it is that although it seems like I can require each named module successfully, I'm not sure that the behavior is deterministic (also, it's not pretty, I'd much rather avoid additional script tags and properly load everything asynchronously).
<script src="scripts/require.js" data-main="app/main.js"></script>
<script src="scripts/datajs-1.1.2.js"></script>
Here, datajs-1.1.2.js defines two modules, as described in the link above and copied below:
// AMD support
if (typeof define === 'function' && define.amd) {
define('datajs', datajs);
define('OData', odata);
} ...