diff --git a/app/node_views/results.html b/app/node_views/results.html
index df675eb..de5816e 100644
--- a/app/node_views/results.html
+++ b/app/node_views/results.html
@@ -211,6 +211,32 @@
+
+
{{notations.network}}
+
Network
+
+
+ -
+ 404 not found: {{phantomasResults.metrics.notFound}}
+
+ -
+ Connections closed: {{phantomasResults.metrics.closedConnections}}
+
+ -
+ Caching disabled: {{phantomasResults.metrics.cachingDisabled}}
+
+ -
+ Caching not specified: {{phantomasResults.metrics.cachingNotSpecified}}
+
+ -
+ Caching too short: {{phantomasResults.metrics.cachingTooShort}}
+
+ -
+ Different domains: {{phantomasResults.metrics.domains}}
+
+
+
+
diff --git a/app/public/scripts/resultsCtrl.js b/app/public/scripts/resultsCtrl.js
index ab1e8b6..6f53dc0 100644
--- a/app/public/scripts/resultsCtrl.js
+++ b/app/public/scripts/resultsCtrl.js
@@ -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) {
diff --git a/phantomas_custom/modules/keepAlive/keepAlive.js b/phantomas_custom/modules/keepAlive/keepAlive.js
new file mode 100644
index 0000000..4550e77
--- /dev/null
+++ b/phantomas_custom/modules/keepAlive/keepAlive.js
@@ -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;
+ }
+ });
+};