Last active
August 7, 2018 09:55
-
-
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)
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
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