[英]My Angular 2 app load very slowly for the first time
I think you are not using any bundle tools like webpack, systemjs..我认为您没有使用任何捆绑工具,例如 webpack、systemjs ..
When you deploy your ng2-app, I should use AOT(ahead of time) compile.当您部署 ng2-app 时,我应该使用 AOT(提前)编译。 I guess you are using JIT(just in time) compile.我猜您正在使用 JIT(及时)编译。
In angular2 guide page,在 angular2 指南页面中,
With AOT, the browser downloads a pre-compiled version of the application.使用 AOT,浏览器会下载应用程序的预编译版本。 The browser loads executable code so it can render the application immediately, without waiting to compile the app first.浏览器加载可执行代码,以便它可以立即呈现应用程序,而无需先编译应用程序。
When you use JIT compile, your browser will download vendor.js which is defined angular2 compiler and it will compile your app just in time.当您使用 JIT 编译时,您的浏览器将下载由 angular2 编译器定义的 vendor.js,它会及时编译您的应用程序。 It will be too slow.会太慢。
I recommend to use AOT compile when you deploy, and use lazy loading for resource size.建议部署时使用AOT编译,资源大小使用延迟加载。
If you are curious about ng2 AOT compile, read this guide.如果您对 ng2 AOT 编译感到好奇,请阅读本指南。
angualar2-cookbook-AOTangualar2-cookbook-AOT
And here is example angular2 app with webpack2 and lazy load.这是带有 webpack2 和延迟加载的示例 angular2 应用程序。
files bundled with aot is smaller than 500KB.与 aot 捆绑的文件小于 500KB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.