Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created May 31, 2017 11:24
Show Gist options
  • Save OliverJAsh/936292234185112fa1040f00057f7ebc to your computer and use it in GitHub Desktop.
Save OliverJAsh/936292234185112fa1040f00057f7ebc to your computer and use it in GitHub Desktop.
Get total image size from HAR file
const fs = require('fs');
const harPath = `${__dirname}/my-site.har`;
const harString = fs.readFileSync(harPath, 'utf-8');
const harParsed = JSON.parse(harString);
const { entries } = harParsed.log;
const isImageEntry = entry => entry.request.url.startsWith('https://images.unsplash.com/photo-');
const sizes = entries
.filter(isImageEntry)
.map(entry => entry.response.content.size);
const add = (a, b) => a + b;
const totalSize = sizes.reduce(add, 0);
console.log(totalSize / 1024);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment