Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active August 7, 2018 09:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/63713fd42a400ff9a3b5535e061962bf to your computer and use it in GitHub Desktop.
Save westonruter/63713fd42a400ff9a3b5535e061962bf to your computer and use it in GitHub Desktop.
Prior to Performance Timeline API getting list of all images in document would require looking at document.images and inspectomg stylesheets to find any referenced background-images; but now with the Performance Timeline API it's easy to get a list of all images (assuming they have image filename extensions)
function getDocumentImages() {
return performance.getEntriesByType('resource')
.map( ( entry ) => entry.name )
.filter( ( url ) => {
const parsedUrl = new URL( url );
return /\.(png|jpe?g|gif|webp|svg)$/i.test( parsedUrl.pathname );
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment