Skip to content

Instantly share code, notes, and snippets.

@rodrigosobrero
Created October 19, 2020 18:10
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 rodrigosobrero/3dda2e18ac20db8a9ebbc2fadb7c8f97 to your computer and use it in GitHub Desktop.
Save rodrigosobrero/3dda2e18ac20db8a9ebbc2fadb7c8f97 to your computer and use it in GitHub Desktop.
Performance API
<!doctype html>
<html>
<head>
</head>
<body onload="loadResources()">
<script>
function loadResources() {
var image1 = new Image();
image1.onload = resourceTiming;
image1.src = 'http://www.w3.org/Icons/w3c_main.png';
}
function resourceTiming() {
var resourceList = performance.getEntriesByType("resource");
console.log(resourceList);
for (i = 0; i < resourceList.length; i++) {
if (resourceList[i].initiatorType == "img") {
console.log(resourceList[i].responseEnd - resourceList[i].startTime);
console.log('---');
}
}
}
</script>
<img id="image0" src="http://www.w3.org/Icons/w3c_home.png">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment