Skip to content

Instantly share code, notes, and snippets.

@cvazac
Created December 21, 2018 20:05
Show Gist options
  • Save cvazac/c9ffb2563fe70c00b0c4479460ab59ae to your computer and use it in GitHub Desktop.
Save cvazac/c9ffb2563fe70c00b0c4479460ab59ae to your computer and use it in GitHub Desktop.
Counting byte savings using Server-Timing
window.addEventListener('load', function() {
let totalBytesSaved = 0
for (const {encodedBodySize, serverTiming} of performance.getEntriesByType('resource')) {
for (const {name, description} of serverTiming || []) {
if (name === 'disk') {
totalBytesSaved += parseInt(description) - encodedBodySize
}
}
}
console.info('Total Bytes Saved:', totalBytesSaved)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment