loadspeed.js计时正确吗?loadspeed.js时间:onload,DomContentLoaded还是别的?
因为我在Chrome中的loaspeed.js和developpor工具栏之间有不同的结果。
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 developper工具栏中的私密模式,我可以看到这个(近两个运行相同)
正如你所看到的,我没有相同的结果(注意:每次),它最终建议加载速度为DOMContentLoaded的事件。
该脚本中是否有“未配置”的功能?
也许我错了,但简单地说,我该如何确定页面加载时间?
比较Date.now()的'的'值是充满了问题,#1是JavaScript的Date对象的分辨率。有关更多信息,请参阅http://stackoverflow.com/questions/131068/in-javascript-is-there-a-source-for-time-with-a-consistent-resolution-in-millis。 – 2013-04-19 20:39:28
谢谢,但我只是想要一个近似的加载时间:分辨率是否为50毫秒无关紧要。 – Cybermaxs 2013-05-06 09:33:49