Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prerendered pages #233

Merged
merged 1 commit into from Jun 19, 2022
Merged

Add support for prerendered pages #233

merged 1 commit into from Jun 19, 2022

Conversation

philipwalton
Copy link
Member

Chrome started rolling out Omnibox prerendering in version 101, via the Prerendering API.

This API has timing implications for prerendered pages—specifically, all load-related metrics should be relative to when the page was "activated" rather than when it started loading (for non-prerendered pages these values are the same).

To support prerendering in this library, this PR updates the onLCP(), onFCP(), and onTTFB() functions to report their value relative to the activationStart time via the Navigation Timing API extension rather than from the time origin of the page.

This PR also adds a new prerender value to the navigationType property of the Metric object, so developers can be aware when prerendering is having an effect on the metric values and filter by just those values (or exclude them from a report if they wish).

One important implication of this change is that the value reported by the library may not match the value reported by the PerformanceEntry object in the Metric.entries array. For example:

{
  name: 'LCP',
  value: 123,  // Doesn't match the value in `entries[0].startTime`.
  navigationType: 'prerender' // New option for the property.
  entries: [
    {
      entryType: 'largest-contentful-paint',
      startTime: 456, // Doesn't match the metric `value`
      // ...
    }
  ],
  // ...
}

The values in the entries array are never modified, so if someone wanted to report both the "raw" LCP value and the LCP value relative to activationStart they could do so using the values from the entries array.

One situation where this may be desirable is the TTFB metric, since prerendered pages will often get their first byte of content before activating, this means the TTFB value will be zero. In these cases developers may choose to report the underlying Navigation Timing API value, including activationStart to help them diagnose and fix network issues. However, when using TTFB as a sub-component of LCP, it's important to compare them using the same start time (e.g. activationStart).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant