Skip to content

Instantly share code, notes, and snippets.

@nekitozzz
Last active April 18, 2016 10:44
Show Gist options
  • Save nekitozzz/37afa52cca78025c6880 to your computer and use it in GitHub Desktop.
Save nekitozzz/37afa52cca78025c6880 to your computer and use it in GitHub Desktop.
Number of style selectors on page
var
styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length,
totalRules = 0;
for (var j = 0; j < totalStyleSheets; j++){
var
styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
totalRulesInStylesheet = rules.length,
totalSelectorsInStylesheet = 0;
totalRules = totalRules + totalRulesInStylesheet;
for (var i = 0; i < totalRulesInStylesheet; i++) {
if (rules[i].selectorText){
totalSelectorsInStylesheet += rules[i].selectorText.split(',').length;
}
}
}
console.log("Total rules: " + totalRules);
@nekitozzz
Copy link
Author

IE8 has limitation for number of style selectors per file (4096).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment