如何以角度查找页面加载时间? [英] How to find page load time in angular?

查看:35
本文介绍了如何以角度查找页面加载时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 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 开发工具来分析 @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 tested. But should run.

这篇关于如何以角度查找页面加载时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆