I’m trying to implement RequireJS in a project and i’m having some issues getting it to work correctly. If i’ve understood this correctly (and otherwise the plugin would be rather pointless), the order plugin downloads the scripts in the correct order, and waits for each model to download before executing the next one. Example:
requirejs.config({
paths: {
'jquery': 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min'
}
});
require(['order!jquery', 'order!models/flyInModal'], function() {
$('.fly-in-modal').flyInModal();
});
That should first download jquery from the path, and after jquery has loaded, continue to load flyInModal.js. Correct?
As of now, this is what’s happening:
- require.js loads
- init-front.js loads
- order.js loads
- jquery starts loading
- flyInModal.js loads
- jquery finishes loading after flyInModal.js has loaded, causing errors because jQuery is missing
Screenshot of chrome dev tools: https://i.stack.imgur.com/5A4fB.png
Have i misunderstood this, or is it working correctly now? I find order.js pretty pointless if it doesn’t wait for the script to finish loading before continuing. Some scripts have a higher latency than others, that’s just how it is.
In RequireJS 2.x
orderhas been deprecated in favour ofshim– http://requirejs.org/docs/api.html#config-shimDetails on why this was removed – https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0#wiki-shim