简体   繁体   English

加载页面时慢角度应用

[英]Slow Angular application when loading page

I'm already seeing this issue for a very long time and searched the web for some solutions but I think I'm not using the correct terminology to identify the problem. 我已经很长时间看到了这个问题,并在网络上搜索了一些解决方案,但是我认为我没有使用正确的术语来识别问题。

I have the following command in my package.json when I run $ npm start 当我运行$ npm start时,我的package.json有以下命令

ng serve --host 0.0.0.0 --disableHostCheck --proxy-config proxy.dev.json --extract-css --show-circular-dependencies false

When I start my application with 'npm start' everything seems to work but after I see 'webpack: Compiled succesfully' it takes a very long time (7-8 seconds) until I actually see a page or my loading screen (a spinner is shown when HTTP calls are occuring). 当我使用'npm start'启动我的应用程序时,一切似乎都可以正常工作,但是当我看到'webpack:成功编译'后,要花很长时间(7-8秒),直到我真正看到页面或加载屏幕(微调器是在进行HTTP调用时显示)。

I'm curious what is happening between the compile being successful and showing the page. 我很好奇编译成功和显示页面之间发生了什么。 After the compile is successful I see a blank page for 7-8 seconds. 编译成功后,我会在7-8秒内看到空白页。

Once the page is shown and I navigate to another page through the menu everything is immediately shown. 显示页面后,我通过菜单导航到另一页面,所有内容都会立即显示。 But when I change the URL manually and hit enter it takes 7-8 seconds to load the page. 但是,当我手动更改URL并按Enter键时,加载页面需要7-8秒。

When this happens I see no activity in my console, network tab or whatever... Anything I could check to identify this 'gap' of no response? 发生这种情况时,我的控制台,“网络”选项卡或任何其他内容都没有任何活动...我可以检查以确认无响应的“空白”的任何内容吗?

Might be worth mentioning, I don't see this issue when serving the application with Apache after ng build --prod . 可能值得一提,在ng build --prod之后使用Apache为应用程序提供服务时,我看不到此问题。

Angular version 5.2.11 Angular-CLI 1.7.4 Angular版本5.2.11 Angular-CLI 1.7.4

Network tab 网络标签 在此处输入图片说明

Performance tab 效果标签 在此处输入图片说明

I'm curious what is happening between the compile being successful and showing the page. 我很好奇编译成功和显示页面之间发生了什么。 After the compile is successful I see a blank page for 7-8 seconds 编译成功后,我会在7-8秒内看到空白页

Your browser needs to download the bundles of your application which must be large depending on your 7-8 seconds of loading. 您的浏览器需要下载应用程序的捆绑包,该捆绑包必须很大,具体取决于您加载7-8秒的时间。 When you $ ng serve , by default you generate the bundles in development mode, which means that the bundles are at their raw size , so they must be large in size in comparison to the bundles in production mode. 当您使用$ ng serve ,默认情况下会在开发模式下生成捆绑包,这意味着捆绑包的大小原始大小 ,因此与生产模式下的捆绑包相比,捆绑包的大小必须更大。

In production mode --prod the bundles are minified so they're small, which means it will take less time to download the bundles. 在生产模式下,-- --prod捆绑包会缩小,因此体积很小,这意味着下载捆绑包所需的时间更少。

NOTE: 注意:

If you want to notice this behavior, in your browser open the console & move to the network tab to see the bundles your browser is downloading & how much time it takes. 如果您想注意到这种现象,请在浏览器中打开控制台并移至“网络”选项卡,以查看浏览器正在下载的捆绑软件以及耗时。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM