We have a non-trivial JS application that consists of many mini-application, is it possible to actually load the script of each mini-application in a lazy manner using require.js?
1 Answer
Yes, you can, and it's one of the main reasons why you would use require.js
$(window).on('start.miniapp1', function () {
require(["miniapp1"], function() {
// Execute code for mini app 1
});
});
5 Comments
Simon Smith
This is incorrect. Modules should be required when needed in this context
Carlos Nuñez
I am assuming each mini application script has it's own closure. Otherwise, ciochPep has not made it clear if each mini application script is some jQuery plugin, has defined it's own namespace, etc. There is actually very little context to his question.
kryger
I believe what @Simon Smith meant was that there should be a "require" in place of "define".
Simon Smith
Indeed. The modules that you need at page load/DOM Ready etc should already be defined. Then you just require them and interact with their methods.
Carlos Nuñez
That's a good suggestion. Thank you, I've revised my answer. if you want to make any edits to it, I will accept them.