javascript get resource api

Solutions on MaxInterview for javascript get resource api by the best coders in the world

showing results for - "javascript get resource api"
Grant
30 Jan 2017
1function calculate_load_times() {
2  // Check performance support
3  if (performance === undefined) {
4    console.log("= Calculate Load Times: performance NOT supported");
5    return;
6  }
7
8  // Get a list of "resource" performance entries
9  var resources = performance.getEntriesByType("resource");
10  if (resources === undefined || resources.length <= 0) {
11    console.log("= Calculate Load Times: there are NO `resource` performance records");
12    return;
13  }
14
15  console.log("= Calculate Load Times");
16  for (var i=0; i < resources.length; i++) {
17    console.log("== Resource[" + i + "] - " + resources[i].name);
18    // Redirect time
19    var t = resources[i].redirectEnd - resources[i].redirectStart;
20    console.log("... Redirect time = " + t);
21
22    // DNS time
23    t = resources[i].domainLookupEnd - resources[i].domainLookupStart;
24    console.log("... DNS lookup time = " + t);
25
26    // TCP handshake time
27    t = resources[i].connectEnd - resources[i].connectStart;
28    console.log("... TCP time = " + t);
29
30    // Secure connection time
31    t = (resources[i].secureConnectionStart > 0) ? (resources[i].connectEnd - resources[i].secureConnectionStart) : "0";
32    console.log("... Secure connection time = " + t);
33
34    // Response time
35    t = resources[i].responseEnd - resources[i].responseStart;
36    console.log("... Response time = " + t);
37
38    // Fetch until response end
39    t = (resources[i].fetchStart > 0) ? (resources[i].responseEnd - resources[i].fetchStart) : "0";
40    console.log("... Fetch until response end time = " + t);
41
42    // Request start until response end
43    t = (resources[i].requestStart > 0) ? (resources[i].responseEnd - resources[i].requestStart) : "0";
44    console.log("... Request start until response end time = " + t);
45
46    // Start until response end
47    t = (resources[i].startTime > 0) ? (resources[i].responseEnd - resources[i].startTime) : "0";
48    console.log("... Start until response end time = " + t);
49  }
50}