简体   繁体   English

Angular 2应用程序的初始加载速度较慢,原因是在angular-cli.json中添加了外部第三方js库

[英]Angular 2 app slow initial load because of added external third party js libs to angular-cli.json

I have gone through angular cli and other links on how to add external js files to the project so finally added it to scripts tag in angular-cli.json. 我已经了解了如何将外部js文件添加到项目中的angular cli和其他链接,因此最终将其添加到angular-cli.json中的scripts标签中。

I am using yFiles graphing library. 我正在使用yFiles图形库。 I have added 10 already minified js files to scripts array in angular-cli.json. 我在angular-cli.json的scripts数组中添加了10个已经缩小的js文件。

After doing 做完之后

ng build --aot --prod

the final build has scripts.bundle.js of size >4MB which makes my app to load slowly/slow initial rendering only because of this file. 最终版本的scripts.bundle.js大小> 4MB,这使我的应用仅由于此文件而缓慢/缓慢加载初始呈现 Any help would be great on how to load these files after showing the initial screen...But what if i want to use these libraries on my initial screen only? 在显示初始屏幕后如何加载这些文件的任何帮助都将非常有用...但是,如果我只想在初始屏幕上使用这些库怎么办?

I am right now having a loading screen, which is there for around 15-18 secs on first load before going into my application. 我现在有一个加载屏幕,进入我的应用程序之前,该屏幕在第一次加载时大约会停留15-18秒。

My first screen itself uses these libs. 我的第一个屏幕本身使用了这些库。

Any help or workarounds would be greatly appreciated ! 任何帮助或解决方法将不胜感激!

If you use the un-minified versions of those scripts, you may find that Angular minimizes them better, but I wouldn't expect too much. 如果使用这些脚本的未缩小版本,则可能会发现Angular可以更好地将它们最小化,但是我期望不会太高。

The real problem is that your adding 4Mb of JavaScript. 真正的问题是您添加了4Mb的JavaScript。 You should probably review that, and see if you really need all of it, or if you can get rid of some. 您可能应该检查一下,看看是否真的需要所有这些,或者可以摆脱一些。

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

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