new rules moved from yslow
This commit is contained in:
parent
a1eb1dc020
commit
8fa2ef74af
|
|
@ -5649,8 +5649,9 @@ YSLOW.registerRuleset({
|
|||
}
|
||||
});
|
||||
/*
|
||||
Rules borrowed from Stoyan Stefanov
|
||||
Rule borrowed from Stoyan Stefanov
|
||||
*/
|
||||
|
||||
var YSLOW3PO = {};
|
||||
YSLOW3PO.is3p = function (url) {
|
||||
|
||||
|
|
@ -5663,7 +5664,8 @@ YSLOW3PO.is3p = function (url) {
|
|||
'code.jquery.com',
|
||||
'platform.linkedin.com',
|
||||
'.disqus.com',
|
||||
'.lognornal.com'
|
||||
'.lognornal.com',
|
||||
'assets.pinterest.com'
|
||||
];
|
||||
var hostname = YSLOW.util.getHostname(url);
|
||||
var re;
|
||||
|
|
@ -5679,8 +5681,8 @@ YSLOW3PO.is3p = function (url) {
|
|||
|
||||
YSLOW.registerRule({
|
||||
id: '_3po_asyncjs',
|
||||
name: 'Load 3rd party JS asyncrhonously',
|
||||
info: "Use the JavaScript snippets that load the JS files asyncrhonously " +
|
||||
name: 'Load 3rd party JS asynchronously',
|
||||
info: "Use the JavaScript snippets that load the JS files asynchronously " +
|
||||
"in order to speed up the user experience.",
|
||||
category: ['js'],
|
||||
config: {},
|
||||
|
|
@ -5776,13 +5778,14 @@ YSLOW.registerRule({
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
YSLOW.registerRule({
|
||||
id: 'cssprint',
|
||||
name: 'Do not load print stylesheets, use @media',
|
||||
info: 'Loading a specific stylesheet for printing slows down the page, ' +
|
||||
'even though it is not used',
|
||||
category: ['css'],
|
||||
config: {},
|
||||
config: {points: 20},
|
||||
url: 'http://sitespeed.io/rules/#cssprint',
|
||||
|
||||
lint: function (doc, cset, config) {
|
||||
|
|
@ -5805,7 +5808,7 @@ YSLOW.registerRule({
|
|||
offenders.push(comps[i]);
|
||||
}
|
||||
}
|
||||
score = 100 - offenders.length * 20;
|
||||
score = 100 - offenders.length * parseInt(config.points, 20);
|
||||
|
||||
return {
|
||||
score: score,
|
||||
|
|
@ -5821,67 +5824,115 @@ YSLOW.registerRule({
|
|||
});
|
||||
|
||||
YSLOW.registerRule({
|
||||
id: 'cssinhead',
|
||||
name: 'CSS in head ',
|
||||
info: 'Make sure css in head is loaded from same domain as document',
|
||||
id: 'cssinheaddomain',
|
||||
name: 'Load CSS in head from document domain',
|
||||
info: 'Make sure css in head is loaded from same domain as document, in order to have a better user experience and minimize dns lookups',
|
||||
category: ['css'],
|
||||
config: {points: 5},
|
||||
url: 'http://sitespeed.io/rules/#cssinhead',
|
||||
config: {points: 10},
|
||||
url: 'http://sitespeed.io/rules/#cssinheaddomain',
|
||||
|
||||
lint: function (doc, cset, config) {
|
||||
var i, len, score, domain, docDomain,
|
||||
cssinhead = [],
|
||||
domains = [],
|
||||
offenders = [],
|
||||
comps = cset.getComponentsByType('css');
|
||||
lint: function (doc, cset, config) {
|
||||
|
||||
var scripts = doc.getElementsByTagName('link'),
|
||||
comps = cset.getComponentsByType('css'),
|
||||
comp, docdomain, src, offenders = {},
|
||||
offender_comps = [],
|
||||
score = 100;
|
||||
|
||||
docdomain = YSLOW.util.getHostname(cset.doc_comp.url);
|
||||
|
||||
for (i = 0, len = comps.length; i< len; i += 1) {
|
||||
|
||||
if (comps[i].containerNode === 'head'){
|
||||
cssinhead.push(comps[i]);
|
||||
}
|
||||
}
|
||||
for (i = 0, len = scripts.length; i < len; i++) {
|
||||
comp = scripts[i];
|
||||
src = comp.href || comp.getAttribute('href');
|
||||
if (src && (comp.rel === 'stylesheet' || comp.type === 'text/css')) {
|
||||
if (comp.parentNode.tagName === 'HEAD') {
|
||||
offenders[src] = 1;
|
||||
}
|
||||
|
||||
docDomain = YSLOW.util.getHostname(cset.doc_comp.url);
|
||||
domains = YSLOW.util.getUniqueDomains(cssinhead);
|
||||
|
||||
for (var i = 0, len = domains.length; i < len; i += 1) {
|
||||
domain = domains[i];
|
||||
if (domain !== docDomain) {
|
||||
offenders.push(domain);
|
||||
}
|
||||
}
|
||||
|
||||
score = 100;
|
||||
if (offenders.length >0) {
|
||||
score -= 1 + offenders.length * parseInt(config.points, 5);
|
||||
for (var i = 0; i < comps.length; i++) {
|
||||
if (offenders[comps[i].url]) {
|
||||
if (docdomain !== YSLOW.util.getHostname(comps[i].url)) {
|
||||
offender_comps.push(comps[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
score: score,
|
||||
message: (offenders.length > 1) ? YSLOW.util.plural(
|
||||
'There %are% %num% stylesheet%s%',
|
||||
offenders.length
|
||||
) + ' in head that are loaded from a domain that is not the document domain' : '',
|
||||
components: offenders
|
||||
};
|
||||
var message = offender_comps.length === 0 ? '' :
|
||||
'The following ' + YSLOW.util.plural('%num% css', offender_comps.length) +
|
||||
' are loaded from a different domain inside head';
|
||||
score -= offender_comps.length * parseInt(config.points, 10)
|
||||
|
||||
return {
|
||||
score: score,
|
||||
message: message,
|
||||
components: offender_comps
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
YSLOW.registerRule({
|
||||
id: 'syncjsinhead',
|
||||
name: 'Never load JS synchronously in head',
|
||||
info: "Use the JavaScript snippets that load the JS files asynchronously in head " +
|
||||
"in order to speed up the user experience.",
|
||||
category: ['js'],
|
||||
config: {points: 10},
|
||||
url: 'http://sitespeed.io/rules/#syncjsinhead',
|
||||
|
||||
lint: function (doc, cset, config) {
|
||||
var scripts = doc.getElementsByTagName('script'),
|
||||
comps = cset.getComponentsByType('js'),
|
||||
comp, offenders = {},
|
||||
offender_comps = [],
|
||||
score = 100;
|
||||
|
||||
for (i = 0, len = scripts.length; i < len; i++) {
|
||||
comp = scripts[i];
|
||||
if (comp.parentNode.tagName === 'HEAD') {
|
||||
if (comp.src) {
|
||||
if (!comp.async && !comp.defer) {
|
||||
offenders[comp.src] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < comps.length; i++) {
|
||||
if (offenders[comps[i].url]) {
|
||||
offender_comps.push(comps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var message = offender_comps.length === 0 ? '' :
|
||||
'The following ' + YSLOW.util.plural('%num% script%s%', offender_comps.length) +
|
||||
' not loaded asynchronously in head:';
|
||||
score -= offender_comps.length * parseInt(config.points, 10)
|
||||
|
||||
return {
|
||||
score: score,
|
||||
message: message,
|
||||
components: offender_comps
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
YSLOW.registerRuleset({
|
||||
id: 'sitespeed',
|
||||
name: 'Sitespeed.io rules v0.8',
|
||||
rules: {
|
||||
ynumreq: {
|
||||
// We are a little harder than standard yslow
|
||||
// the number of scripts allowed before we start penalizing
|
||||
max_js: 2,
|
||||
// number of external stylesheets allowed before we start penalizing
|
||||
max_css: 2,
|
||||
// number of background images allowed before we start penalizing
|
||||
max_cssimages: 3
|
||||
// We are a little harder than standard yslow
|
||||
// the number of scripts allowed before we start penalizing
|
||||
max_js: 2,
|
||||
// number of external stylesheets allowed before we start penalizing
|
||||
max_css: 2,
|
||||
// number of background images allowed before we start penalizing
|
||||
max_cssimages: 3
|
||||
},
|
||||
yemptysrc: {},
|
||||
yexpires: {},
|
||||
|
|
@ -5907,7 +5958,8 @@ YSLOW.registerRuleset({
|
|||
_3po_asyncjs: {},
|
||||
_3po_jsonce: {},
|
||||
cssprint: {},
|
||||
cssinhead: {}
|
||||
cssinheaddomain: {},
|
||||
syncjsinhead: {}
|
||||
},
|
||||
weights: {
|
||||
ynumreq: 8,
|
||||
|
|
@ -5935,7 +5987,8 @@ YSLOW.registerRuleset({
|
|||
_3po_asyncjs: 10,
|
||||
_3po_jsonce: 10,
|
||||
cssprint: 1,
|
||||
cssinhead: 8
|
||||
cssinheaddomain: 8,
|
||||
syncjsinhead: 10
|
||||
}
|
||||
|
||||
});/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue