如何以角度查找页面加载时间? [英] How to find page load time in angular?
本文介绍了如何以角度查找页面加载时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是在angular2 +中查找页面加载时间的正确方法吗? 我不这么认为,这只是路由更改之间的时差.我们如何为其添加页面DOM内容加载时间.??
Is this the right way to find page load time in angular2+?? I don't think so, It's just the time difference between the route change.How can we add the page DOM content load time to it.??
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 dev工具来分析性能,如@AurA所述
在以上所有您可以初始化的脚本中分别进行
you can definitely use chrome dev tools to analyse perfomance as mentioned by @AurA
separately in the above all scripts you can initialise
<script type="text/javascript">
var timerStart = Date.now();
</script>
以及主要部分
ngAfterViewInit(){
console.log("Time until reaching run phase: ", Date.now() - $window.timerStart);
}
Havent经过测试.但应该运行.
Havent tested. But should run.
这篇关于如何以角度查找页面加载时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文