Skip to content

Instantly share code, notes, and snippets.

@eokoneyo
Last active January 31, 2020 12:51
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 eokoneyo/659e6629880a7e724b4086026699097f to your computer and use it in GitHub Desktop.
Save eokoneyo/659e6629880a7e724b4086026699097f to your computer and use it in GitHub Desktop.
List external scripts being loaded on the HelloFresh Website
const resources = window.performance.getEntriesByType('resource');
const isHF = (resource) => /\w*\.(hellofresh|cloudflare)\.\w*/.test(resource);
const nonHFResources = resources.reduce((result, resource) => {
return !isHF(resource.name) ? result.concat(resource) : result
}, []);
const externalThirdPartyScripts = nonHFResources
.filter(val => val.initiatorType === 'script')
.map(list => `${list.name} - ${list.transferSize ? Math.round(list.transferSize/1024)+'KB' : 'N/A'}`);
console.log('%s external scripts that aren\'t classified as required for the app were loaded!! 🛠', externalThirdPartyScripts.length);
console.log(externalThirdPartyScripts.join('\n'));
// the size of the javascript file would be listed as "N/A" if the server doesn't send the "Timing-Allow_Origin" header
// see https://w3c.github.io/resource-timing/#sec-timing-allow-origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment