gpt4 book ai didi

angular - 如何以 Angular 查找页面加载时间?

转载 作者:太空狗 更新时间:2023-10-29 19:36:02 25 4
gpt4 key购买 nike

这是在 angular2+ 中查找页面加载时间的正确方法吗?我不这么认为,这只是路由更改之间的时间差。我们如何将页面 DOM 内容加载时间添加到它。??

this.router.events.subscribe((val) => {
const navigationComplete = val instanceof NavigationEnd;
const navigationStart = val instanceof NavigationStart;
if(navigationStart){
this.navigationStartTime = (new Date).getTime();
}
if (navigationComplete) {
this.currentPage = this.router.url; // Current page route
this.currentLocation = (this.platformLocation as any).location.href; // Current page url
let endTime = (new Date).getTime();
this.pageLoadTime = Number(endTime) - Number(this.navigationStartTime); // Page load time
}
});

最佳答案

你绝对可以使用 chrome 开发工具来分析@AurA 提到的性能
在上面的所有脚本中分别进行初始化

<script type="text/javascript">
var timerStart = Date.now();
</script>

在主组件中

ngAfterViewInit(){
console.log("Time until reaching run phase: ", Date.now() - $window.timerStart);
}

还没有测试过。但应该运行。

关于angular - 如何以 Angular 查找页面加载时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49934797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com