cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Why does a named module load dependencies? #215

Closed webpro closed 10 years ago

webpro commented 10 years ago

For instance, the following define() is "just" a definition (as expected).

define(['bar'], function(bar) {

});

Yet this named module immediately tries to resolve/fetch "bar":

define('foo', ['bar'], function(bar) {

});
unscriptable commented 10 years ago

Hey @webpro,

For better or worse, curl.js tries to fetch dependencies as soon as possible. AMD does not specify when dependencies should be fetched or when the factory function should be executed. Therefore, in the early days I decided to make curl.js do things as soon as possible. This made a huge difference in our development cycles when using IE (orders of magnitude performance difference on our large project).

curl needs to know the current module's ID before it can correctly normalize dependencies. Therefore, if it knows the id in advance, then it fetches the dependencies immediately.

As I've been rewriting curl (or its successor?), I've been careful to only do things just-in-time. This makes the code simpler and avoids some tricky situations. Are you having a specific issue caused by curl's "eager" fetching?

-- John

webpro commented 10 years ago

Thanks for the detailed clarification.