Resource Timing API
You'll learn how to inspect load times for every individual resource your page fetches—scripts, images, stylesheets, and more.
What This API Does
The Resource Timing API gives you granular timing data for each resource your page loads. While Navigation Timing (which you just learned) tells you about the overall page lifecycle, Resource Timing zooms in on individual assets: that hero image, the analytics script, your CSS bundle, or that third-party font file.
Think of it like tracking a delivery truck (Navigation Timing) versus tracking every individual package inside it (Resource Timing).
How It Works
Use performance.getEntriesByType('resource') to retrieve an array of timing entries—one per resource. Each entry contains detailed metrics:
const resources = performance.getEntriesByType('resource');
resources.forEach(resource => {
console.log(resource.name); // URL of the resource
console.log(resource.duration); // Total load time
console.log(resource.transferSize); // Bytes transferred
});
Key Timing Properties
Each resource entry includes familiar phases:
fetchStart: When the browser started fetchingdomainLookupStart/End: DNS lookup timeconnectStart/End: TCP connection timerequestStart: When request was sentresponseStart/End: When response arrivedduration: Total time from start to finish
Practical Uses
Find slow resources:
const slowResources = resources.filter(r => r.duration > 1000);
console.log('Resources taking over 1 second:', slowResources);
Analyze cache hits:
const fromCache = resources.filter(r => r.transferSize === 0);
console.log('Cached resources:', fromCache.length);
Key Takeaway: The Resource Timing API lets you measure and analyze every asset your page loads, helping you identify bottlenecks like slow third-party scripts, oversized images, or cache misses.