Last active
January 31, 2020 12:51
-
-
Save eokoneyo/659e6629880a7e724b4086026699097f to your computer and use it in GitHub Desktop.
List external scripts being loaded on the HelloFresh Website
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
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