1

I'm using in my project require.js and it's plugin use.js.

require.config({
// Initialize the application with the main application file
deps: ["main"],

paths: {
    // JavaScript folders
    libs: "../assets/js/libs",
    plugins: "../assets/js/plugins",

    // Libraries
    jquery: "../assets/js/libs/jquery",
    underscore: "../assets/js/libs/underscore",
    backbone: "../assets/js/libs/backbone",
    jqueryUI: "../assets/js/libs/jqueryUI",
    jquerySlider: "../assets/js/libs/slider",
    jqueryMouseWheel: "../assets/js/libs/jquery.mousewheel",    
    jquerySelectBox: "../assets/js/libs/selectBox",
    jqueryMouse: "../assets/js/libs/mouse",
    bookReader: "../assets/js/libs/newReader",

    // Shim Plugin
    use: "../assets/js/plugins/use"
},

use: {
    backbone: {
        deps: ["use!underscore", "jquery"],
        attach: "Backbone"
    },

    underscore: {
        attach: "_"
    },

    jqueryUI: {
        deps: ["jquery"]
    },

    jquerySlider: {
        deps: ["jquery", "jqueryMouse"]
    },

    jquerySelectBox: {
        deps: ["jquery"]
    },

    jqueryMouse: {
        deps: ["jquery", "jqueryUI"]
    },

    jqueryMouseWheel: {
        deps: ["jquery", "jqueryUI"]
    },

    bookReader: {
        deps: ["jquery", "jqueryUI", "jqueryMouse", "jquerySlider", "jqueryMouseWheel", "jquerySelectBox"],
        attach: "Reader"
    }
}
});

The problem is that scripts start load simultaneously, and because of that there are unmet dependencies, often there are these two errors

Uncaught TypeError: Object function (a, b) {return new e.fn.init (a, b, h)} has no method 'widget': 4444/assets/js/libs/mouse.js: 15
Uncaught TypeError: Cannot read property 'mouse' of undefined: 4444/assets/js/libs/slider.js: 20

Once the files are in the cache, the problem no longer occurs. So, my question. How do I specify that the script must loaded consistently?

It is possible to build scripts that wrap them into one file. But this option is not very desirable

Thank you!

1 Answer 1

1

Have a look at this AMD loader plugin called STEP, it allows you to load scripts in sequential order.

https://github.com/requirejs/step

Sign up to request clarification or add additional context in comments.

1 Comment

Its not clean on how to install step in requirejs. I tried to include step.js to be called before and after require.js but neither worked. any suggestions?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.