Skip to content

Instantly share code, notes, and snippets.

@jeffreybiles
Created April 7, 2015 22:11
Show Gist options
  • Save jeffreybiles/53308b32db5abf5db412 to your computer and use it in GitHub Desktop.
Save jeffreybiles/53308b32db5abf5db412 to your computer and use it in GitHub Desktop.
hacky way to count number of CSS rules
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
var totalCount = 0
for (var i = 0; i < document.styleSheets.length; i++) {
totalCount += countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
var count = 0;
if (sheet && sheet.cssRules) {
for (var j = 0, l = sheet.cssRules.length; j < l; j++) {
if( !sheet.cssRules[j].selectorText ) {
continue;
}
count += sheet.cssRules[j].selectorText.split(',').length;
}
}
console.log(count, sheet.href);
return count;
}
console.log(totalCount);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment