Created
September 3, 2013 23:43
-
-
Save JoshuaJones/6431077 to your computer and use it in GitHub Desktop.
Log out the number of rules and selectors in stylesheets loaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var selectorsCount = function () { | |
var styleSheets = document.styleSheets, | |
totalStyleSheets = styleSheets.length; | |
console.group('Stylesheet Rules/Selector Debug Info'); | |
console.log('----------------------------------'); | |
try { | |
for (var j = 0; j < totalStyleSheets; j++) { | |
var styleSheet = styleSheets[j], | |
rules = styleSheet.cssRules, | |
totalRules = rules.length, | |
totalSelectors = 0; | |
for (var i = 0; i < totalRules; i++) { | |
if (rules[i].selectorText) { | |
totalSelectors += rules[i].selectorText.split(',').length; | |
} | |
} | |
console.log('Stylesheet: ' + styleSheet.href); | |
console.log('Total Rules: ' + totalRules); | |
console.log('Total Selectors: ' + totalSelectors); | |
console.log('----------------------------------'); | |
} | |
} catch(e) { | |
console.log('Tried to log something stylesheet related, but failed', e); | |
} | |
console.groupEnd(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment