Whether to return camelCase keys. Defaults to false, which returns snake_case keys.
The collected page-load metrics.
This function uses the PerformanceNavigationTiming API to get page load time data.
The PerformanceNavigationTiming API provides more accurate and detailed information about page load time than the deprecated PerformanceTiming API.
Usage:
import { getPerformance } from "mazey";
// `camelCase: false` (default) returns snake_case keys such as `a_b`.
// `camelCase: true` returns camelCase keys such as `aB`.
getPerformance()
.then(res => {
console.log(JSON.stringify(res));
})
.catch(console.error);
Output:
{"source":"PerformanceNavigationTiming","os":"others","os_version":"","device_type":"pc","network":"4g","screen_direction":"","unload_time":0,"redirect_time":0,"dns_time":0,"tcp_time":0,"ssl_time":0,"response_time":2,"download_time":2,"first_paint_time":288,"first_contentful_paint_time":288,"dom_ready_time":0,"onload_time":0,"white_time":0,"render_time":0,"decoded_body_size":718,"encoded_body_size":718}
Results:
| Attribute | Description | Type | Values |
|---|---|---|---|
| dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
| tcp_time | Connection Negotiation | number | connectEnd - connectStart |
| response_time | Requests and Responses | number | responseStart - requestStart |
| white_time | White Screen | number | responseStart - navigationStart |
| dom_ready_time | Dom Ready | number | domContentLoadedEventStart - navigationStart |
| onload_time | Onload | number | loadEventStart - navigationStart |
| render_time | EventEnd | number | loadEventEnd -navigationStart |
| unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
| redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
| ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
| download_time | Download | number | (Optional) responseEnd - responseStart |
Get page-load metrics from the Navigation Timing APIs.