2

The 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.

1 Answer 1

6

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.

4
  • This works perfectly. It is possible to import the order plugin and RequireJS too with a CDN address? May 27, 2011 at 8:03
  • Great to hear. I am not aware of both order.js and require.js being on a CDN at the moment, although I do want to lobby for at least require.js once the 1.0 release is done. require.js is up on cdnjs.com but I do not have any data on how reliable it is, or the people that back that CDN. I like what they are trying to do though.
    – jrburke
    May 27, 2011 at 17:07
  • Why do you need nested require calls? couldn't we just include order!src/app in the dependencies array? Thanks
    – simao
    Aug 10, 2011 at 14:33
  • Thomas from cdnjs.com chiming in here. We are partnered with a company called cloudflare.com which has doubled up our reliability. But I do believe that if things can go wrong they will hence why I opened a thread on google groups(groups.google.com/group/requirejs/browse_thread/thread/…). Hopefully someone can write a detailed solution for using a CDN and fall back local scripts using require.js Sep 1, 2011 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.