开发者

Requirejs' order does not work with priority config and CDN dependencies

The 开发者_C百科following main.js code do not respect the order of priorities (sometimes underscore.js is not loaded when backbone.js needs it):

require({
    baseUrl:'/scripts',
    priority:[
        "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js",
        "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js",
        "http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js",
        "http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"
    ]
    },["src/app"], 
    function (app) {
        app.start();
});

Adding order! before those CDN dependencies fails with a order.js not found error.


I recently updated the RequireJS docs, but I have not pushed the change to the site yet:

The "priority" configuration cannot load resources loaded by plugins. So to accomplish what you are trying to do, you can just nest require() calls, which will give you the behavior you want:

require(
    {
        baseUrl:'/scripts'
    },
    [
        "require",
        "order!http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js",
        "order!http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js",
        "order!http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js",
        "order!http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"

    ], 
    function (require) {
        require(["src/app"], function (app) {
            app.start();
        });
    }
);

This assumes you have the order plugin in the /scripts/order.js location.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜