Routes should allow to load modules/controllers on demand
When you route to a specific location, the template for that route is loaded on demand. There should also be a feature to specify a module or controller script that will be loaded when the user routes to the given location.
There is a solution using require.js (https://github.com/matys84pl/angularjs-requirejs-lazy-controllers), but it adds another library and another nesting level (angular module definitions within require.js module definitions)
As for the use case:
- Increase the initial startup time by loading scripts only when they are needed.
- Only serve scripts to users that have the right to see the route they are used in.
- Enhanced modularity.
+1
+1
+1
+1
+1
+1, but even the ability to lazy load modules at all would be nice.
+1
I have made a very small change to angular that allows modules to load after bootstrap, which is more general than the lazy load controller approach at https://github.com/matys84pl/angularjs-requirejs-lazy-controllers.
Put these lines in createInjector(), just before the return statement (tested this on 1.2.0-rc.2):
instanceInjector.loadNewModules = function (mods) { forEach(loadModules(mods), function(fn) { instanceInjector.invoke(fn || noop); }); };
Then, after the module source is loaded dynamically (i use requireJS for now) just call $injector.loadNewModules(['nameOfModuleJustLoaded']), and all the components get registered nicely with angular (well the few things i've tested so far seem to work perfectly).
I'll try to make a PR out of this one day, when i get a spare moment...
:+1:
This (or just lazy loading at all indeed) is absolutely vital for single-page apps.
+1 I applied this workaround and solved my problem http://ify.io/lazy-loading-in-angularjs/ . Hope this help.
+1, with the ability to do another config for the loaded module and register new routes.
+1
+1
+1
:heart: google,this function is basic and obvious
+1
+1
+1
+1
+1