Home  >  Q&A  >  body text

angular.js - AngularJS 项目中如何实现按需加载js文件

如题

请有实践经验的大神帮帮忙,小弟跪谢!

我想大声告诉你我想大声告诉你2736 days ago621

reply all(4)I'll reply

  • 某草草

    某草草2017-05-15 16:53:21

    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

    reply
    0
  • ringa_lee

    ringa_lee2017-05-15 16:53:21

    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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 16:53:21

    Use with requirejs

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

    Already used in company projects, the effect is good

    reply
    0
  • 迷茫

    迷茫2017-05-15 16:53:21

    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

    reply
    0
  • Cancelreply