0

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 1

1

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
    });
});
Sign up to request clarification or add additional context in comments.

5 Comments

This is incorrect. Modules should be required when needed in this context
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.
I believe what @Simon Smith meant was that there should be a "require" in place of "define".
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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.