angular.js - AngularJS 项目中如何实现按需加载js文件
我想大声告诉你
我想大声告诉你 2017-05-15 16:51:21
0
4
594

如题

  • 在AngularJS项目中js文件越来越多的情况下,如何做到按需加载;
  • 目前调研结果是使用RequireJS或者Browserify;

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

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!