Skip to content

Instantly share code, notes, and snippets.

@FurkanKozen
Created May 15, 2020 14:42
Show Gist options
  • Save FurkanKozen/b6aa15ae5251f416612a68f0a9ce6423 to your computer and use it in GitHub Desktop.
Save FurkanKozen/b6aa15ae5251f416612a68f0a9ce6423 to your computer and use it in GitHub Desktop.
Simple use of Network and Resource Timing APIs in JavaScript
//Collects performance metrics for HTML documents.
performance.getEntries();
performance.getEntriesByType("navigation")[0];
performance.getEntriesByType("navigation")[0].serverTiming[0];
//Collects performance metrics for document-dependent resources.
//Stuff like style sheets, scripts, images, et cetera.
performance.getEntriesByType("resource")[0];
performance.getEntriesByType("resource")[0].serverTiming[0];
performance.getEntriesByType("resource")[1];
performance.getEntriesByType("resource")[1].serverTiming[1];
//Indexing continues until the last resource
//serverTiming only works if server is setting header values on requests.
//https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing
//https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment