johnpapa / ng-demos

variety of angular demos
MIT License
1.7k stars 961 forks source link

Dynamic loading of js files using RequireJS framework #44

Open mg-arrow opened 9 years ago

mg-arrow commented 9 years ago

Is it possible to modify the current modular application and include RequireJS to handle dynamic loading of the javascript files required for the specific modules ?

The current structure would not well in case of the large level size application because all the files will need to be loaded in the beginning.

jhulick commented 9 years ago

+1

This is doable with the ng-demos apps, as I had implemented an integration of ng-demos/module app with requirejs this past summer using the approach specified by Dan Wahlin in this blog post:

http://weblogs.asp.net/dwahlin/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs

For me, it was needed for security purposes, to validate that the user had authority to access each module/controller other than the dashboard. One thing I did not do at the time was fix the karma runner to load tests properly using RequireJs. I'd like to hear John's feedback about this approach too, and I may be able to find my sample and post to a forked version if requested.

jhulick commented 9 years ago

fwiw, there is a provider here that would help with loading angular modules on demand: https://github.com/ocombe/ocLazyLoad