AngularJS:ocLazyLoad与Requirejs [英] Angularjs: ocLazyLoad vs Requirejs

查看:65
本文介绍了AngularJS:ocLazyLoad与Requirejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个大型的Angluar项目,显然,我们需要一种方法来延迟加载脚本.

I'm working on a big angluar project and obviously we need a way to lazy load our scripts.

我以前使用过require.js,效果很好,但是问题是,在连接并缩小文件后,我们得到了150万个js文件.

I've worked with require.js before and it's quite good, but the problem is that after we concatenating and minifying our files, we got a 1.5M js file.

所以我刚遇到 OcLazyload ,它看起来很有希望,但是我在网络上看到了很多同时使用require和ocLazyLoad的示例,我对为什么要同时使用两者感到有些困惑.他们俩不是在做同一件事吗?

So i just encountered OcLazyload and it looks promising but i saw a lot of examples on the web that use both require and ocLazyLoad, I'm a bit confused as to why you would want to use both. Aren't they both doing the same thing?

推荐答案

您同时需要ocLazyLoad和RequireJS,因为现在您需要处理两个单独的模块概念-javascript模块和有角度的内部模块.

You need both ocLazyLoad and RequireJS because with you now deal with two separate module concepts - your javascript modules and the angular internal modules.

在初始引导后,angularjs不再允许注册新的模块和组件,例如指令和控制器(至少不使用标准方式).

After the initial bootstrap, angularjs doesn't allow registering new modules and components like directives and controllers anymore (at least not using the standard way).

RequireJS仅加载javascript文件,但未在此新代码中注册新的angular模块和组件

RequireJS only loads javascript files but it doesn't register the new angular modules and components in this new code

ocLazyLoad的作用是允许您使用诸如RequireJS之类的第三方模块加载器加载其他文件,更重要的是,它在延迟加载的代码中按角度注册了新模块和组件.

What ocLazyLoad does is to allow you to load your additional files using a third party module loader like RequireJS and the more important thing - it registers in angular the new modules and components in the lazily loaded code.

总而言之-您可以仅使用RequireJS来延迟加载代码,但不能仅使用RequireJS来加载角度模块和组件.需要额外的工作,例如ocLazyLoad执行的工作.

In summary - you can lazily load code using only RequireJS, but you can't load angular modules and components only using RequireJS. There is a need for extra work, like this performed by ocLazyLoad.

这篇关于AngularJS:ocLazyLoad与Requirejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆