Question

How does define() treat traditional javascript files?

For example,

a.js

define(['b', 'c.js', 'd.js'], function(b){ /* code */});

When does c.js or d.js get fetched and loaded? Will it be loaded and available in function(b){}?

I know that the order is not preserved. Will the order plugin help for this?
The docs say

It is not needed for scripts that use define() to define modules

but does that apply to traditional scripts as well?

Thanks

Was it helpful?

Solution

For plain Javascript files that do not define modules, they will be loaded and executed in arbitrary order. In your example above, there's no guarantee that c.js will execute before d.js. But by the time your callback executes, both will be loaded.

If you need c.js and d.js to execute in order, use the order plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top