I am currently writing a example application with require.js and now found LazyLoad.js.
Require.js
require(["modul1", "modul2"],function(Modul1, Modul2){
LazyLoad.js
LazyLoad.js(["modul1", "modul2"],function(Modul1, Modul2){
Where is the difference between these both?
For me it is important to be able to load modules async and the dependency management should be done automatically.
If you want automatic dependency management then LazyLoad is not appropriate. LazyLoad is appropriate if you just need a runtime loader and don't care about:
- Defining modules
- Tracking dependencies. From the lazyload github (emphasis mine):
- An option for build-time optimization
It looks like LazyLoad just directly loads URLs and doesn't check for path mappings or if that module is already loaded. So I think your 2nd code snippet would probably look like this:Whereas RequireJS would let you do something like this:
And also define shims for what files need to be loaded before these modules.