角度5个应用程序文件将在不到1秒的时间内下载。但渲染初始页面需要10秒

时间:2018-04-12 08:45:06

标签: angular performance nginx angular5

Angular 5应用程序整体初始有效负载大小为1.7 MB,可在不到2秒的时间内下载,但之后需要8-10秒才能绘制主页。

enter image description here

1 个答案:

答案 0 :(得分:0)

我得到了上述问题的解决方案。

在package.json

中添加了一个脚本
"build-prod": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod --aot true --vendor-chunk true --common-chunk true --env=prod --delete-output-path=false",

在服务器上构建和部署时执行AOT后,当您点击example.com时,它首先下载整个块并立即开始执行它。而当你使用你的构建 - 然后在点击example.com浏览器下载后,整个块需要时间来编译和执行。

此外,如果您在模块方面有角度2+应用程序将有所帮助,这称为延迟加载(延迟路由加载)

希望这会有所帮助