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

Multiple modules in "preload module" #230

Closed webpro closed 9 years ago

webpro commented 10 years ago

When there are multiple define() calls in a bundle, configured to be preloaded in preloads, I'm getting no output at all.

But when using the same modules as a regular dependency, it works fine.

Say, this is preloadLib.js (bundled, so named modules):

define('a', function(){
    return 'a';
});

define('preloadLibs', ['a'], function(){
    return 'preloadLibs';
});

..then this fails:

curl.config({
    preloads: ['preloadLibs']
});

define('b', function(){
    return 'b';
})

curl(['b'], function() {
    console.log(arguments);
});

..while this is OK (without the preloads config):

curl(['preloadLibs','c'], function(b, c) {
    console.log(arguments);
});

Not getting any output from the failing case (also not with an errback).

So, I was wondering whether this difference in behavior is on purpose? I thought I should be able to preload a built bundle.

unscriptable commented 10 years ago

Hey @webpro,

I hadn't considered this case at all. Still, I'm a bit surprised it doesn't work (and gives no error indication).

I may have some time soon to dig in to see what's happening, but I really would like to wait until I've refactored curl. Are you ok with a not-pre-bundled-preload solution for now?

-- John

webpro commented 10 years ago

Thanks @unscriptable.

I'd rather wait for a next version, as this kinda ruins the curl setup in our project (gist + #216). No hard feelings, but I simply stick to require.js until I can finish the migration to curl. Unbundled preloads is an option of course, but a hassle to setup and probably undoes any performance gains.

I'm also willing to dig into curl myself for this, but it sounds like the refactoring is a serious one..?

unscriptable commented 10 years ago

Curious: why would unbundled preloads be a hassle or performance problem? cram.js will bundle them into a single file along with the app's non-preload modules.

webpro commented 10 years ago