Skip to content

Instantly share code, notes, and snippets.

@palkan
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palkan/beaf6bc52b125cc7a26c to your computer and use it in GitHub Desktop.
Save palkan/beaf6bc52b125cc7a26c to your computer and use it in GitHub Desktop.
Page classnames stats
window._collect_css = (function(){
var ALPHABET_SIZE=36, classnames={},
data = {
total_elements: null,
total_classes: null,
avg_length: null,
compressed_length: null,
total_class_length: 0,
total_class_count: 0,
total_size: 0,
compressed_size: 0
};
elements = document.querySelectorAll('*');
data.total_elements = elements.length;
[].slice.apply(elements).forEach(function(el) {
[].slice.apply(el.classList).forEach(function(cname){
data.total_class_length+=cname.length;
data.total_class_count++;
classnames[cname] ? classnames[cname]++ : classnames[cname]=1;
});
});
data.total_classes = Object.keys(classnames).length;
data.avg_length = Math.ceil(data.total_class_length / data.total_class_count);
data.compressed_length = Math.ceil(Math.log(data.total_classes) / Math.log(ALPHABET_SIZE));
data.total_size = Math.round(data.total_class_length / 1024);
data.compressed_size = Math.round((data.total_class_count*data.compressed_length)/1024);
for(key in data){
if(!data.hasOwnProperty(key)) continue;
console.log(key, data[key]);
}
return data;
});
window._collect_css();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment