Created
January 25, 2018 14:03
-
-
Save kdzwinel/c0f3953faeedc768d642894044b92328 to your computer and use it in GitHub Desktop.
__LIGHTHOUSE_JSON__ analysis script
This file contains hidden or 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
(function() { | |
function strSize(obj) { | |
const string = JSON.stringify(obj); | |
return string ? string.length : 0; | |
} | |
const lhj = __LIGHTHOUSE_JSON__; | |
const fullSize = strSize(lhj); | |
const maxLevels = 5; | |
function analyzeKeys(obj, level = 0) { | |
Object.keys(obj) | |
.map(field => ({ | |
name: field, | |
size: strSize(obj[field]) | |
})) | |
.sort((a, b) => b.size - a.size) | |
.forEach(field => { | |
const percentage = Math.round((field.size * 100)/fullSize); | |
const value = field.name === 'name' && (typeof obj[field.name] === 'string') ? ` ${obj[field.name]}` : ''; | |
const label = `${' '.repeat(level)}↪ ${field.name}:${value} ${percentage}%`; | |
if (percentage > 0 && level < maxLevels) { | |
console.groupCollapsed(label); | |
analyzeKeys(obj[field.name], level + 1); | |
console.groupEnd(); | |
} else { | |
console.log(label); | |
} | |
}); | |
} | |
analyzeKeys(lhj); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run in the console of the raport page to get a following breakdown of
__LIGHTHOUSE_JSON__
: