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

fallback to local copy of a library #244

Closed szepeviktor closed 10 years ago

szepeviktor commented 10 years ago
'jquery'     => '//ajax.googleapis.com/ajax/libs/jquery/10.1.2/jquery.min.js',
'jquery-local'     => 'jquery.min'

How do I fall back to local version? It has a different name and all dependecies will fail.

szepeviktor commented 10 years ago

anything like this? http://requirejs.org/docs/api.html#pathsfallbacks

unscriptable commented 10 years ago

Hello @szepeviktor!

This seems like a useful feature and easy to add via an add-on loader. However, I would implement it differently from RequireJS. What are your thoughts about the following configuration?

curl.config({
    paths: {
        jquery: {
            location: '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',
            config: { loader: 'curl/loader/fallback', fallback: 'jquery.min' }
        }
    }
});

-- John

szepeviktor commented 10 years ago

Thank you very much! I would add these cases to this issue:

Basicly decide what to load based on a condition.

szepeviktor commented 10 years ago

Is it possible to build in this loader?

unscriptable commented 10 years ago

Hey @szepeviktor,

Sniffing the environment and then deciding which library to load seems a bit much for a loader, imho. You could create a wrapper module for this, though. Something like this:

// "jquery" module
(function (moduleId) {
    // wrap / passthru of actual jquery that is chosen
    define([moduleId], function (jquery) { return jquery; });
}(
    // do some feature sniffing here
    document.addEventListener ? '//cdn.jquery.com/jquery2.1.1.min' : '//cdn.jquery.com/jquery1.9.1.min'
));

How does that look to you?

-- John

szepeviktor commented 10 years ago

It seems to be solved.