Angularjs: ocLazyLoad vs Requirejs Angularjs: ocLazyLoad vs Requirejs angularjs angularjs

Angularjs: ocLazyLoad vs Requirejs


You can use RequireJS with ocLazyLoad but I don't recommend it, it's just possible because people asked me to do it and it was easy to integrate.You don't need RequireJS because ocLazyLoad includes its own loaders for js/css/templates files, and it can load any kind of files, not just angular modules.

If you want to lazy load Angular modules you will need a lib to register them with Angular (or wait Angular 1.5 that will allow you to do it).

Bottom line is: you can use RequireJS with ocLazyLoad, or just ocLazyLoad (recommended), but you can't use just RequireJS


You need both ocLazyLoad and RequireJS because with you now deal with two separate module concepts - your javascript modules and the angular internal modules.

After the initial bootstrap, angularjs doesn't allow registering new modules and components like directives and controllers anymore (at least not using the standard way).

RequireJS only loads javascript files but it doesn't register the new angular modules and components in this new code

What ocLazyLoad does is to allow you to load your additional files using a third party module loader like RequireJS and the more important thing - it registers in angular the new modules and components in the lazily loaded code.

In summary - you can lazily load code using only RequireJS, but you can't load angular modules and components only using RequireJS. There is a need for extra work, like this performed by ocLazyLoad.