简体   繁体   English

我的 Angular 2 应用程序第一次加载非常缓慢

[英]My Angular 2 app load very slowly for the first time

在此处输入图片说明

Why is my Angular app loading so slow for the first time?为什么我的 Angular 应用程序第一次加载如此缓慢? What is causing the compiler.umd.js to take almost 5 seconds to load before other files are allowed to load?是什么导致compiler.umd.js在允许加载其他文件之前需要将近 5 秒的时间加载?

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。

angular2-webpack2-aot angular2-webpack2-aot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 应用程序的第一页加载速度很慢 - Angular Application's first page very slowly to load 我的 angular 2 应用程序需要很长时间才能为第一次使用的用户加载,我需要帮助来加快速度 - My angular 2 app takes a long time to load for first time users, I need help to speed it up 在角通用 (SSR) 模式下加载第一页需要很长时间 - First page takes a very long time to load in angular universal (SSR) mode Angular 7非常缓慢地加载登录后组件 - Angular 7 loading the after login component very slowly Angular - 仅触发第一次加载的代码 - Angular - Code to trigger only first time Load Internet Explorer(10,11)加载Angular 2应用程序非常慢 - Internet explorer (10, 11) very slow to load Angular 2 app Angular2 - 选择器“my-app”不匹配任何元素(仅在第一次加载时) - Angular2 - The selector "my-app" did not match any elements (only on first load) 在Angular中加载Google Map,第一次不要加载 - Load Google Map in Angular, dosen't load at the first time Angular 2 应用程序仅在 Chrome DevTools 打开时反应非常缓慢 - Angular 2 Application reacting very slowly only while Chrome DevTools is open Angular 5应用首次在Safari上加载不正确 - Angular 5 app loads incorrectly first time on Safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM