【发布时间】:2013-04-03 21:21:51
【问题描述】:
loadspeed.js 的时间是否正确?
因为我在 loaspeed.js 和 Chrome 中的 developerpor 工具栏之间有不同的结果。
var page = require('webpage').create(),
system = require('system'),
t, address;
page.viewportSize = { width: 1024, height: 768 };
if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit(1);
} else {
t = Date.now();
address = system.args[1];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
t = Date.now() - t;
console.log('#1 Loading time ' + t + ' msec');
t = Date.now();
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
t = Date.now() - t;
console.log('#2 Loading time ' + t + ' msec');
}
phantom.exit();
});
}
});
}
运行脚本给我
>phantomjs.exe loadspeed.js http://www.google.com
#1 Loading time 348 msec
#2 Loading time 202 msec
在私有模式下使用 Chrome 开发人员工具栏,我可以看到这一点(两次运行几乎相同)
如您所见,我没有相同的结果(注意:每次),它最终建议 加载速度测量 DOMContentLoaded 事件。
该脚本中是否有任何“未配置”功能?
也许我错了,但很简单,我怎样才能测量页面加载时间?
【问题讨论】:
-
比较
Date.now()的值充满了问题,#1 是 JavaScript Date 对象的分辨率。请参阅stackoverflow.com/questions/131068/… 了解更多信息。 -
谢谢,但我只想要一个大概的加载时间:分辨率是否为 50 毫秒并不重要。
标签: javascript phantomjs headless