I am developing a web app using jQuery and RequireJS for dependency management. Some of my Javascript files have to be loaded lazily when some events happend, so I have written these events like this:
$("#pf-content").on("click", "#link", function() {
require(["another_js"], function(another_js){
//Initialization code from another_js.js
});
});
The above code works, but I understand it's not the best way to do this, because the entire code has to be filled with "require" statements, wherever a lazy load would be neccesary.
Is there any other more elegant way to lazy load a Javascript file using jQuery and RequireJS?
Thank you very much in advance