简体   繁体   English

网站加载问题:Angular 6项目加载时间过多

[英]Site loading issue: Angular 6 project taking too much time to load

后期加载性能图

In the above picture its clear that My application is taking too much time(3 mins as shown in the image) to load for the first time. 在上图中,很明显,我的应用程序花费了太多时间(如图中的3分钟)来首次加载。 I am not able to find the actual reason. 我找不到实际原因。

Some details about my application: 有关我的应用程序的一些细节:

  1. There are total only 13 components in my project. 我的项目中总共只有13个组件。
  2. I have not used lazy loading, because its not big enough in my point of view to use lazy loading. 我没有使用延迟加载,因为从我的观点来看,它还不够大,无法使用延迟加载。 Because after build the main.js file size is just 2.4 MB 因为构建后main.js文件的大小仅为2.4 MB
  3. To minify the size i have even deleted the spec.ts files and unwanted .scss files. 为了减小大小,我什至删除了spec.ts文件和不需要的.scss文件。
  4. There are 6 .svg files in the whole project. 整个项目中有6个.svg文件。
  5. This is the command I am using for building. 这是我用于构建的命令。 ' ng-build --prod --aot ' 'ng-build --prod --aot'

If any further details is needed I ll provide , Please help me out in finding the actual reason behind the delay. 如果需要其他详细信息,请帮我找出延迟原因。

Take the advantage of angular router and module lazy loading. 利用角度路由器和模块延迟加载的优势。 For example create module of relevant component and when the vie is visited load the specific js file 例如,创建相关组件的模块,并在访问vie时加载特定的js文件

In the example when customer route is visited it will load the relevant js file so is other module 在示例中,当访问customer路线时,它将加载相关的js文件,其他模块也会加载

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: './customers/customers.module#CustomersModule'
  },
  {
    path: 'orders',
    loadChildren: './orders/orders.module#OrdersModule'
  }
];

Also you can run ng build --prod . 您也可以运行ng build --prod This will compress the code, will eliminate dead code 这将压缩代码,将消除无效代码

  1. It can be 13 components with 6K lines of code. 它可以是13个具有6K行代码的组件。 Number of components don't matter, code complexity does. 组件数量无关紧要,代码复杂度却无关紧要。

  2. Lazy loading doesn't reduce the bundle size : lazy loading is the features that loads the Javascript when asked instead of when received 延迟加载不会减小包的大小:延迟加载是在询问时而不是在收到 加载Javascript的功能

  3. spec files don't appear in the build, and .scss files are compiled into JS (making no difference in the final build, whether you use inline styling or URL styling) spec文件没有出现在构建中,并且.scss文件被编译到JS中(无论您使用内联样式还是URL样式,最终版本都没有影响)

  4. See point n° 1 见第1点

  5. Again, similar to point n° 1, it depends on the commands you run and the code you need to compile. 再次,类似于点n°1,它取决于您运行的命令和需要编译的代码。

I can't see images, but have you ran a lighthouse audit on your application ? 我看不到图像,但是您是否对应用程序进行了灯塔审核 It might tell you what you can improve. 它可能会告诉您可以改进的地方。

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

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