这是在 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/