new SurfNPerfRT()
Surf-N-Perf methods for working with the Resource Timing API
Methods
-
staticSurfNPerfRT.SNPRTProto.duration(name|resource, startMark, endMark, options){Number}
-
Returns the duration between two marks for the specified resource
Name Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
startMark
String name of the first mark
endMark
String name of the second mark
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number duration between the two specified marks, false if a mark has a 0 value (CORS request without a Timing-Allow-Origin header), undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getBlockingTime(name|resource, options){Number}
-
Return the "missing periods" (non-zero durations) that occur between connectEnd and requestStart (when waiting on a Keep-Alive TCP connection to reuse), or between fetchStart and domainLookupStart (when waiting on things like the browser’s cache) of the specified resource
See "Blocking Time" section of http://nicj.net/resourcetiming-in-practice/ for additional detailsName Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the time the resource was blocked. Returns false for a CORS request without a Timing-Allow-Origin header, undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getEnd(name|resource, options){Number}
-
Shorthand for
window.performance.getEntriesByName(name, "resource")[0].responseEnd
Name Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number time immediately after the user agent receives the last byte of the response or immediately before the transport connection is closed, whichever comes first. Returns undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getFullRequestLoadTime(name|resource, options){Number}
-
Shorthand for
window.performance.getEntriesByName(name, "resource")[0].duration
Note this included blocking time. If you want blocking time filtered out, usegetNetworkTime
Name Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the difference between responseEnd
andstartTime
, respectively. Returns undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getLastResource(name){PerformanceResourceTiming}
-
Get the last resource from window.performance.getEntriesByName for the specified name
Name Type Description name
String resource name (i.e. full URL)
Returns:
Type Description PerformanceResourceTiming resource object, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getNetworkDuration(name|resource, options){Number}
-
Return the amount of time the network was actively fetching the first resource from name
Essentially, this is the duration minus blocking time
See http://www.stevesouders.com/blog/2014/11/25/serious-confusion-with-resource-timing/ for additional detailsName Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the combined time for DNS lookup, TCP handshake, Request to Server, and Server Response. Returns false for a CORS request without a Timing-Allow-Origin header, undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getNetworkTime(name|resource, options){Number}
-
Return the time for App Cache, DNS & TCP (and any time in between) of the specified resource
For a CORS request without a Timing-Allow-Origin header, the value will allows be falseName Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the difference between fetchStart
andconnectEnd
, respectively. Returns false for a CORS request without a Timing-Allow-Origin header, undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getOrigins(options){Array}
-
Get the array of all the origins of the resources returned by window.performance.getEntriesByType with no duplicates
Name Type Description options
Object optional Includes either a "whitelist" key with a single string or an array of origins as the value that will be used to return only those items that are in the list of origins, or a "blacklist" key with a single string or an array of origins as the value that will be used to filter out those origins
Returns:
Type Description Array Array of strings of origins of resources, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getResource(name|resource, index|options){PerformanceResourceTiming}
-
Get the first resource from window.performance.getEntriesByName for the specified name
Optional 2nd arugment can return a resource other than the first (useful if you request the same resource multiple times, either to request updated data in a Single Page App, or when making a Cross Origin request that requires an initial OPTIONS request)Name Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
index|options
String | Object optional Returns the resource from the specified index. Index should be a 0-based integer or the special keyword 'last', which will return the last item. If passing an object instead of a string, the object property name is 'index'. Ignored if the first argument is a PerformanceResourceTiming resource
Returns:
Type Description PerformanceResourceTiming resource object, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getResourceCount(name){number}
-
Returns total count of all PerformanceResourceTimings for the page, filtered by name if specified
Name Type Description name
String optional resource name (i.e. full URL)
Returns:
Type Description number total number of resources, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getResourceNamesFromOrigin(origin){Array}
-
Returns an array of all the names from the PerformanceResouceTimings from the specified origin
Name Type Description origin
String the canonical form of the origin of a location (i.e. protocol + hostname + port)
Returns:
Type Description Array Array of names from the origin's resources, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getResources(name){Array}
-
Returns all PerformanceResourceTimings for the page, filtered by name if specified
Name Type Description name
String optional resource name (i.e. full URL)
Returns:
Type Description Array Array of PerformanceResourceTimings for the specified resource name, or all PerformanceResourceTimings if no name is provided, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getResourcesFromOrigin(origin, property){Array}
-
Returns an array of all the PerformanceResouceTimings from the specified origin
Name Type Description origin
String the canonical form of the origin of a location (i.e. protocol + hostname + port)
property
String optional if specified, only return that property of each resource instead of the entire PerformanceResourceTiming resource
Returns:
Type Description Array Array of PerformanceResourceTimings or specific PerformanceResourceTiming properties from the origin, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getServerTime(name|resource, options){Number}
-
Return the time for the request & response of the specified resource
For a CORS request without a Timing-Allow-Origin header, the value will allows be falseName Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the difference between requestStart
andresponseEnd
, respectively. Returns false for a CORS request without a Timing-Allow-Origin header, undefined if the resource is not found, or null if Resource Timing is not supported -
staticSurfNPerfRT.SNPRTProto.getStart(name|resource, options){Number}
-
Shorthand for
window.performance.getEntriesByName(name, "resource")[0].startTime
Name Type Description name|resource
String | PerformanceResourceTiming resource name (i.e. full URL) or an actual PerformanceResourceTiming PerformanceEntry resource object
options
Object optional Can contain an 'index' property and/or a 'decimalPlaces' property. 'index' will allow you to calculate the duration for a resource other than the first instance of that name. 'index' should be a 0-based integer or the special keyword 'last', which will return the last item. Index is ignored if the first argument is a PerformanceResourceTiming resource. 'decimalPlaces' will round the result to that number of decimal places (otherwise, an integer is returned)
Returns:
Type Description Number the time immediately before the user agent starts to queue the resource for fetching, undefined if the resource is not found, or null if Resource Timing is not supported