Closed fizerkhan closed 9 years ago
Can you provide the code that gives you these results? What makes this even more strange is the fact that there are less metrics in the results for http://google.com/
(jsErrors
is the last one).
@macbre This is the code that i used.
var urls = [ 'http://ping.com', 'http://google.com'];
require('async').mapSeries(urls, function(urlString, cb) {
require('phantomas')(urlString, {}, function(err, json, results) {
cb(err, json && json.metrics);
});
}, function(err, results) {
if (err) {
console.error('Error in processing url', err);
return;
}
console.log(results);
});
Sorry, i removed some metrics from above result to improve the visibility.
The code above works for me (I'm on devel
branch, removed most of the metrics below just to give the comparison):
[ [ 'http://bing.com',
{ requests: 24,
gzipRequests: 0,
postRequests: 0,
httpsRequests: 0,
notFound: 0,
bodySize: 35354,
contentLength: 525032,
httpTrafficCompleted: 1782,
timeToFirstByte: 244,
timeToLastByte: 340,
ajaxRequests: 0,
htmlCount: 2,
htmlSize: 59807,
cssCount: 0,
cssSize: 0,
jsCount: 13,
jsSize: 97697,
jsonCount: 1,
jsonSize: 711,
imageCount: 7,
imageSize: 366817,
videoCount: 0,
videoSize: 0,
webfontCount: 0,
webfontSize: 0} ],
[ 'http://google.com',
{ requests: 10,
gzipRequests: 0,
postRequests: 0,
httpsRequests: 0,
notFound: 0,
bodySize: 18749,
contentLength: 66666,
httpTrafficCompleted: 431,
timeToFirstByte: 105,
timeToLastByte: 134,
ajaxRequests: 0,
htmlCount: 3,
htmlSize: 3753,
cssCount: 0,
cssSize: 0,
jsCount: 1,
jsSize: 2463,
jsonCount: 0,
jsonSize: 0,
imageCount: 5,
imageSize: 60450,
videoCount: 0,
videoSize: 0,
webfontCount: 0,
webfontSize: 0} ] ]
Finally i found the reason for weird behaviour. I don't know this is a bug.
As you said, above code works for me too. But in my case, i just abstracted the phantomas option
above the async call. This does not work.
Following code does not work.
var phantomasOption = { };
var urls = [ 'http://ping.com', 'http://google.com'];
require('async').mapSeries(urls, function(urlString, cb) {
// Please note that i uses abstracted phantomas option
require('phantomas')(urlString, phantomasOption, function(err, json, results) {
cb(err, json && json.metrics);
});
}, function(err, results) {
if (err) {
console.error('Error in processing url', err);
return;
}
console.log(results);
});
If i moved phantomas option inside the callback, everything works fine
var urls = [ 'http://ping.com', 'http://google.com'];
require('async').mapSeries(urls, function(urlString, cb) {
// Please note that i moved phantomas option inside the callback.
var phantomasOption = { };
require('phantomas')(urlString, phantomasOption, function(err, json, results) {
cb(err, json && json.metrics);
});
}, function(err, results) {
if (err) {
console.error('Error in processing url', err);
return;
}
console.log(results);
});
We are running multiple URLs by
async.each
to get report of them. Even though i get the results, results has same value incount
andsize
I tried to
bing.com
andgoogle.com
usingasync.each
. I am getting following valuesTake a look at values of
htmlCount
,htmlSize
,cssCount
,cssSize
,jsCount
,jsSize
,imageCount
,imageSize
. They have same values.