gpt4 book ai didi

node.js - Nodejs + phantomjs 与纯 phantomjs - 页面加载时间

转载 作者:搜寻专家 更新时间:2023-10-31 22:35:48 27 4
gpt4 key购买 nike

我最近在探索 nodejs 和 phantomjs,并编写了一个小代码来测量页面加载时间。我发现页面加载时间在 nodejs 中包装的 phantomjs 代码与纯 phantomjs 代码之间有所不同。下面是代码:phantomjs和nodejs对比:

Node :

var http = require('http'),
phantom = require('phantom');
url = require("url");

http.createServer(function (request, response) {
var start = Date.now();

request.on('end', function () {
phantom.create(function(ph) {
ph.createPage(function(page) {
var _get = url.parse(request.url, true).query;

page.open(_get[url], function(status) {
if (status == 'success') {
var time = Date.now() - start;
console.log(time);
}
});
});
});
});
}).listen(80,'');

幻影:

var page = require('webpage').create();
var system = require('system');

var address = system.args[1];
var time = 0;
var start = Date.now();

page.open(address, function (status) {
time = Date.now() - start;
console.log(time + '');
});

通过 phantomjs 测试站点时,时间通常要长 4 倍。有什么想法吗?

最佳答案

PhantomJS 不支持输出数据,它只打开一个网页。 <强> phantomjs-node 以下列方式连接它们 - 它创建一个 ExpressJS 实例并通过其 socket.io 传输数据并使用另外两个库。数据如下:

网页 > Phantom.js > dnode + node-browserify > Express.js > Socket.io > Node.js

我现在阅读关于 node-webkit 的速度和性能也有同样的问题,这就是支持 Node.js 模块的原生 WebKit。

关于node.js - Nodejs + phantomjs 与纯 phantomjs - 页面加载时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13881770/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com