angular.js - How to load js files on demand in AngularJS projects
我想大声告诉你
我想大声告诉你 2017-05-15 16:51:21
0
4
636

As mentioned

  • When there are more and more js files in AngularJS projects, how to load them on demand;
  • The current research result is to use RequireJS or Browserify;

Please help someone with practical experience, thank you!

我想大声告诉你
我想大声告诉你

reply all(4)
某草草

I have used RequireJS + AngularJS implementation before, but I feel there is no need to use AMD mode to load JS files. Some personal opinions:

  • AMD loading looks good, but in the final production environment, it is recommended to compress the JS file into one file, which may be faster
  • AngularJS itself can be written as a module for loading. If you find it inconvenient to manage, then take a look at the arrangement of folders in your project, the naming of files, etc. It feels more convenient to manage the front-end code in these ways

AMD's loading looks good, but under normal circumstances, there is not much need to use AMD to load JS, CSS, HTML, etc.

Just a personal suggestion, there are many discussions on the Internet about whether to use AMD mode, just use the one you like best

BTW, the above suggestions are based on PC as the platform

左手右手慢动作

I wrote a gadget, which is actually a web slides, made by requirejsangularJs.
Online address: http://leftstick.github.io/front-end-slides/,
Source code: https://github.com/leftstick/front-end-slides/tree/gh-pages

Because it’s not big, it may be helpful to your understanding

过去多啦不再A梦

Use with requirejs

http://github.com/treri/angular-require

Already used in company projects, the effect is good

迷茫

It is recommended to use angular-async-loader to implement asynchronous loading of angular modules, including various controllers, filters, services, directives, etc., and also supports angular-ui-router

http://my.oschina.net/sub/blog/513255/
https://github.com/subchen/angular-async-loader

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template