4 ms·
What I'd really like to see in AngularJS is some sort of asynchronous module system a la AMD. Doesn't have to be AMD, but some way to not have to load a whole
by craigching 12y ago
What I'd really like to see in AngularJS is some sort of asynchronous module system a la AMD. Doesn't have to be AMD, but some way to not have to load a whole app in memory at once. I thought I saw a design document that mentioned they were considering this for AngularJS 2.0, does anyone know more about it?
I do know that you can use requirejs, does anyone have any experience to share using requirejs and angularjs?
- SanderMak 12y agoWe use angular with RequireJS, though we don't (yet) load any Angular modules lazily because it is not supported by Angular. There are workarounds (like https://github.com/marcoslin/angularAMD https://github.com/marcoslin/angularAMD) which I have no experience with. We do load external libs (like MathJax, which is comparatively huge) lazily where possible. Our AMD modules are actually TypeScript modules that generate the AMD wrapper. Works great, and makes for a very clean and modular codebase. In the end, we use r.js to concat and minify most of it (everything except the lazily loaded libs) down to a single file. Including Angular templates, using https://www.npmjs.org/package/gulp-angular-templatecache https://www.npmjs.org/package/gulp-angular-templatecache which can output the templates as initialization scripts inside and AMD wrapper as well.
- aikah 12y agoBut you're not using async (angular)module loading.Angular modules cannot be loaded async in.You might be able to inject services after the app is bootstrapped but it involves using global variables,which totally defeat the purpose of dependency injection.
- SanderMak 12y agoIndeed, that's what my first sentence implies. Note that this doesn't prevent you from lazily loading other JS libs when using them inside Angular modules.