|
@@ -66,82 +66,23 @@ var policies = {
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
- /*"DOMaccesses": {
|
|
|
+ "DOMaccesses": {
|
|
|
"tool": "jsExecutionTransformer",
|
|
|
"label": "DOM access",
|
|
|
- "message": "<p>TODO</p><p>TODO</p>",
|
|
|
+ "message": "<p>This metric counts the number of calls to DOM related functions (both native DOM functions and jQuery functions) on page load.</p><p>The more your JavaScript code accesses the DOM, the slower the page will load.</p><p>Try, as much as possible, to have an HTML page fully generated by the server instead of making changes with JS.</p><p>Try to reduce the number of queries by refactoring your JavaScript code.</p><p>Binding too many events also has a cost. Try to use <a href=\"https://learn.jquery.com/events/event-delegation/\" target=\"_blank\">event delegation</a> as much as possible.</p>",
|
|
|
"isOkThreshold": 50,
|
|
|
- "isBadThreshold": 2000,
|
|
|
+ "isBadThreshold": 1500,
|
|
|
"isAbnormalThreshold": 3000,
|
|
|
"hasOffenders": false
|
|
|
- },*/
|
|
|
- "DOMinserts": {
|
|
|
- "tool": "phantomas",
|
|
|
- "label": "DOM inserts",
|
|
|
- "message": "<p>Working with the DOM in JavaScript triggers layout calculations and slows down the page.</p><p>Try, as much as possible, to have an HTML page fully generated by the server instead of making changes with JS.</p>",
|
|
|
- "isOkThreshold": 10,
|
|
|
- "isBadThreshold": 400,
|
|
|
- "isAbnormalThreshold": 1000,
|
|
|
- "hasOffenders": true,
|
|
|
- "offendersTransformFn": function(offenders) {
|
|
|
- return {
|
|
|
- count: offenders.length,
|
|
|
- list: offenders.map(function(offender) {
|
|
|
- var parts = /^"(.*)" ?appended ?to ?"(.*)"$/.exec(offender);
|
|
|
-
|
|
|
- if (!parts) {
|
|
|
- debug('DOMinserts offenders transform function error with "%s"', offender);
|
|
|
- return {
|
|
|
- parseError: offender
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- insertedElement: offendersHelpers.domPathToDomElementObj(parts[1]),
|
|
|
- receiverElement: offendersHelpers.domPathToDomElementObj(parts[2])
|
|
|
- };
|
|
|
- })
|
|
|
- };
|
|
|
- }
|
|
|
},
|
|
|
- "DOMqueries": {
|
|
|
- "tool": "phantomas",
|
|
|
- "label": "DOM queries",
|
|
|
- "message": "<p>DOM queries are like looking in a large catalog of items. Even if the browsers made progress on the performances of queries, websites often make hundreds of them.</p><p>Try to reduce the number of queries by refactoring your JavaScript code.</p><p>Avoid also to have a read query between two write queries. To be able to reduce the number repaints and optimize performances, browsers buffer the DOM writing operations and treat them in bulk. But each time a DOM reading is asked, the browser needs to empty the buffer. This can be particularly slow inside a loop.</p>",
|
|
|
- "isOkThreshold": 50,
|
|
|
- "isBadThreshold": 1000,
|
|
|
- "isAbnormalThreshold": 2000,
|
|
|
- "hasOffenders": false
|
|
|
- },
|
|
|
- "DOMqueriesWithoutResults": {
|
|
|
- "tool": "phantomas",
|
|
|
- "label": "DOM queries without result",
|
|
|
- "message": "<p>Number of queries that return no result.</p><p>It suggests the query is not used on the page, probably because it is some dead code.</p><p>Or maybe the code is trying to find an HTML block that is not always here. Look at the JS Timeline to see if the scripts correctly figures out the HTML block is not here and immediatly stops interacting further with the DOM.</p>",
|
|
|
+ "queriesWithoutResults": {
|
|
|
+ "tool": "jsExecutionTransformer",
|
|
|
+ "label": "Queries without result",
|
|
|
+ "message": "<p>Number of queries that return no result. Both native and jQuery DOM requests are counted.</p><p>It suggests the query is not used on the page, probably because it is some dead code.</p><p>Or maybe the code is trying to find an HTML block that is not always here. Look at the JS Timeline to see if the scripts correctly figures out the HTML block is not here and immediatly stops interacting further with the DOM.</p>",
|
|
|
"isOkThreshold": 0,
|
|
|
"isBadThreshold": 100,
|
|
|
"isAbnormalThreshold": 200,
|
|
|
- "hasOffenders": true,
|
|
|
- "offendersTransformFn": function(offenders) {
|
|
|
- return {
|
|
|
- count: offenders.length,
|
|
|
- list: offenders.map(function(offender) {
|
|
|
- var parts = /^(.*) ?\(in ?(.*)\) ?using ?(.*)$/.exec(offender);
|
|
|
-
|
|
|
- if (!parts) {
|
|
|
- debug('DOMqueriesWithoutResults offenders transform function error with "%s"', offender);
|
|
|
- return {
|
|
|
- parseError: offender
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- query: parts[1],
|
|
|
- context: offendersHelpers.domPathToDomElementObj(parts[2]),
|
|
|
- fn: parts[3]
|
|
|
- };
|
|
|
- })
|
|
|
- };
|
|
|
- }
|
|
|
+ "hasOffenders": false
|
|
|
},
|
|
|
"DOMqueriesAvoidable": {
|
|
|
"tool": "phantomas",
|
|
@@ -175,35 +116,6 @@ var policies = {
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
- "eventsBound": {
|
|
|
- "tool": "phantomas",
|
|
|
- "label": "Events bound",
|
|
|
- "message": "<p>Binding too many events has a cost.</p><p>It can be avoided by using \"event delegation\". Instead of binding events on each element one by one, events delegation binds them on the top level document element and uses the bubbling principle. It will imperceptibly slow down the event when it occurs, but the loading of the page will speed-up.</p>",
|
|
|
- "isOkThreshold": 100,
|
|
|
- "isBadThreshold": 800,
|
|
|
- "isAbnormalThreshold": 1500,
|
|
|
- "hasOffenders": true,
|
|
|
- "offendersTransformFn": function(offenders) {
|
|
|
- return {
|
|
|
- count: offenders.length,
|
|
|
- list: offenders.map(function(offender) {
|
|
|
- var parts = /^"(.*)" ?bound ?to ?"(.*)"$/.exec(offender);
|
|
|
-
|
|
|
- if (!parts) {
|
|
|
- debug('eventsBound offenders transform function error with "%s"', offender);
|
|
|
- return {
|
|
|
- parseError: offender
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- eventName: parts[1],
|
|
|
- element: offendersHelpers.domPathToDomElementObj(parts[2])
|
|
|
- };
|
|
|
- })
|
|
|
- };
|
|
|
- }
|
|
|
- },
|
|
|
"eventsScrollBound": {
|
|
|
"tool": "phantomas",
|
|
|
"label": "Scroll events bound",
|
|
@@ -351,9 +263,9 @@ var policies = {
|
|
|
"tool": "phantomas",
|
|
|
"label": "Global variables",
|
|
|
"message": "<p>It is a bad practice because they clutter up the global namespace. If two scripts use the same variable name in the global scope, it can cause conflicts and it is generally hard to debug.</p><p>Global variables also take a (very) little bit longer to be accessed than variables in the local scope of a function.</p>",
|
|
|
- "isOkThreshold": 10,
|
|
|
- "isBadThreshold": 50,
|
|
|
- "isAbnormalThreshold": 200,
|
|
|
+ "isOkThreshold": 30,
|
|
|
+ "isBadThreshold": 100,
|
|
|
+ "isAbnormalThreshold": 400,
|
|
|
"hasOffenders": true,
|
|
|
"offendersTransformFn": function(offenders) {
|
|
|
return {
|
|
@@ -389,17 +301,17 @@ var policies = {
|
|
|
score = 70;
|
|
|
} else if (value.indexOf('1.8.') === 0) {
|
|
|
score = 50;
|
|
|
- } else if (value.indexOf('1.7.') === 0) {
|
|
|
+ } else if (value.indexOf('1.7') === 0) {
|
|
|
score = 40;
|
|
|
- } else if (value.indexOf('1.6.') === 0) {
|
|
|
+ } else if (value.indexOf('1.6') === 0) {
|
|
|
score = 30;
|
|
|
- } else if (value.indexOf('1.5.') === 0) {
|
|
|
+ } else if (value.indexOf('1.5') === 0) {
|
|
|
score = 20;
|
|
|
- } else if (value.indexOf('1.4.') === 0) {
|
|
|
+ } else if (value.indexOf('1.4') === 0) {
|
|
|
score = 10;
|
|
|
- } else if (value.indexOf('1.3.') === 0) {
|
|
|
+ } else if (value.indexOf('1.3') === 0) {
|
|
|
score = 0;
|
|
|
- } else if (value.indexOf('1.2.') === 0) {
|
|
|
+ } else if (value.indexOf('1.2') === 0) {
|
|
|
score = 0;
|
|
|
} else {
|
|
|
debug('Unknown jQuery version "%s"', value);
|
|
@@ -433,12 +345,21 @@ var policies = {
|
|
|
"jQueryFunctionsUsed": {
|
|
|
"tool": "jsExecutionTransformer",
|
|
|
"label": "jQuery usage",
|
|
|
- "message": "<p>This is the number of different jQuery functions called on load. This rule is not trying to blame you for using jQuery too much, but the opposite.</p><p>If only a few functions are used, why not trying to get rid of jQuery? Have a look at <a href=\"http://youmightnotneedjquery.com/\" target=\"_blank\">http://youmightnotneedjquery.com</a>.</p>",
|
|
|
+ "message": "<p>This is the number of different core jQuery functions called on load. This rule is not trying to blame you for using jQuery too much, but the opposite.</p><p>If only a few functions are used, why not trying to get rid of jQuery? Have a look at <a href=\"http://youmightnotneedjquery.com/\" target=\"_blank\">http://youmightnotneedjquery.com</a>.</p>",
|
|
|
"isOkThreshold": 15,
|
|
|
"isBadThreshold": 6,
|
|
|
"isAbnormalThreshold": 0,
|
|
|
"hasOffenders": true
|
|
|
},
|
|
|
+ "jQueryCallsOnEmptyObject": {
|
|
|
+ "tool": "jsExecutionTransformer",
|
|
|
+ "label": "Calls on empty objects",
|
|
|
+ "message": "<p>This metric counts the number of jQuery functions called on an empty jQuery object. The call was useless.</p><p>This can be helpful to detect dead or unused code.</p>",
|
|
|
+ "isOkThreshold": 1,
|
|
|
+ "isBadThreshold": 100,
|
|
|
+ "isAbnormalThreshold": 180,
|
|
|
+ "hasOffenders": false
|
|
|
+ },
|
|
|
"jQueryNotDelegatedEvents": {
|
|
|
"tool": "jsExecutionTransformer",
|
|
|
"label": "Events not delegated",
|
|
@@ -446,7 +367,7 @@ var policies = {
|
|
|
"isOkThreshold": 1,
|
|
|
"isBadThreshold": 100,
|
|
|
"isAbnormalThreshold": 180,
|
|
|
- "hasOffenders": true
|
|
|
+ "hasOffenders": false
|
|
|
},
|
|
|
"cssParsingErrors": {
|
|
|
"tool": "phantomas",
|
|
@@ -1024,7 +945,7 @@ var policies = {
|
|
|
"tool": "phantomas",
|
|
|
"label": "Font count",
|
|
|
"message": "<p>Fonts are loaded on the critical path of the head. Load as few as possible.</p>",
|
|
|
- "isOkThreshold": 0,
|
|
|
+ "isOkThreshold": 1,
|
|
|
"isBadThreshold": 3,
|
|
|
"isAbnormalThreshold": 5,
|
|
|
"hasOffenders": true,
|