Added new Network related notations

This commit is contained in:
Gaël Métais
2014-09-19 17:08:46 +02:00
parent e593d80f51
commit 41ddd4961f
3 changed files with 91 additions and 1 deletions
+26
View File
@@ -211,6 +211,32 @@
</ul>
</div>
</div>
<div>
<div ng-class="notations.network">{{notations.network}}</div>
<div class="notation">Network</div>
<div class="criteria">
<ul>
<li ng-if="phantomasResults.metrics.notFound">
404 not found: {{phantomasResults.metrics.notFound}}
</li>
<li ng-if="phantomasResults.metrics.closedConnections">
Connections closed: {{phantomasResults.metrics.closedConnections}}
</li>
<li ng-if="phantomasResults.metrics.cachingDisabled">
Caching disabled: {{phantomasResults.metrics.cachingDisabled}}
</li>
<li ng-if="phantomasResults.metrics.cachingNotSpecified">
Caching not specified: {{phantomasResults.metrics.cachingNotSpecified}}
</li>
<li ng-if="phantomasResults.metrics.cachingTooShort">
Caching too short: {{phantomasResults.metrics.cachingTooShort}}
</li>
<li ng-if="phantomasResults.metrics.domains">
Different domains: {{phantomasResults.metrics.domains}}
</li>
</ul>
</div>
</div>
</div>
</div>
+28 -1
View File
@@ -75,7 +75,8 @@ app.controller('ResultsCtrl', function ($scope) {
jQueryLoading: getJQueryLoadingScore(),
cssComplexity: getCSSComplexityScore(),
badCss: getBadCssScore(),
requests: requestsScore()
requests: requestsScore(),
network: networkScore()
};
}
@@ -373,6 +374,32 @@ app.controller('ResultsCtrl', function ($scope) {
return note;
}
function networkScore() {
var note = 'A';
var score = $scope.phantomasResults.metrics.notFound * 25 +
$scope.phantomasResults.metrics.closedConnections * 10 +
$scope.phantomasResults.metrics.cachingDisabled * 2 +
$scope.phantomasResults.metrics.cachingNotSpecified +
$scope.phantomasResults.metrics.cachingTooShort / 2 +
$scope.phantomasResults.metrics.domains;
if (score > 20) {
note = 'B';
}
if (score > 40) {
note = 'C';
}
if (score > 60) {
note = 'D';
}
if (score > 80) {
note = 'E';
}
if (score > 100) {
note = 'F';
}
return note;
}
function parseBacktrace(str) {
@@ -0,0 +1,37 @@
/**
* Analyzes if HTTP responses keep the connections alive.
*/
exports.version = '0.1';
exports.module = function(phantomas) {
'use strict';
phantomas.setMetric('closedConnections'); // @desc requests not keeping the connection alive and slowing down the next request @offenders
var closedConnectionHosts = {};
phantomas.on('recv', function(entry, res) {
var connectionHeader = (entry.headers.Connection || '').toLowerCase();
// Taking the protocol in account, in case the same domain is called with two different protocols.
var host = entry.protocol + '://' + entry.domain;
if (connectionHeader.indexOf('close') >= 0) {
// Don't blame it immediatly, wait to see if the connection is needed a second time.
closedConnectionHosts[host] = entry.url;
}
});
phantomas.on('send', function(entry, res) {
var host = entry.protocol + '://' + entry.domain;
var previousClosedConnection = closedConnectionHosts[host];
if (previousClosedConnection) {
// There was a closed connection. We can blame it safely now!
phantomas.incrMetric('closedConnections');
phantomas.addOffender('closedConnections', previousClosedConnection);
closedConnectionHosts[host] = null;
}
});
};