You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> FID is deprecated and will be removed in the next major release.
46
49
47
50
<aname="installation"><a>
48
51
<aname="load-the-library"><a>
@@ -63,7 +66,8 @@ You can install this library from npm by running:
63
66
npm install web-vitals
64
67
```
65
68
66
-
_**Note:** If you're not using npm, you can still load `web-vitals` via `<script>` tags from a CDN like [unpkg.com](https://unpkg.com). See the [load `web-vitals` from a CDN](#load-web-vitals-from-a-cdn) usage example below for details._
69
+
> [!NOTE]
70
+
> If you're not using npm, you can still load `web-vitals` via `<script>` tags from a CDN like [unpkg.com](https://unpkg.com). See the [load `web-vitals` from a CDN](#load-web-vitals-from-a-cdn) usage example below for details.
67
71
68
72
There are a few different builds of the `web-vitals` library, and how you load the library depends on which build you want to use.
69
73
@@ -81,7 +85,8 @@ onINP(console.log);
81
85
onLCP(console.log);
82
86
```
83
87
84
-
_**Note:** in version 2, these functions were named `getXXX()` rather than `onXXX()`. They've [been renamed](https://github.com/GoogleChrome/web-vitals/pull/222) in version 3 to reduce confusion (see [#217](https://github.com/GoogleChrome/web-vitals/pull/217) for details) and will continue to be available using the `getXXX()` until at least version 4. Users are encouraged to switch to the new names, though, for future compatibility._
88
+
> [!NOTE]
89
+
> In version 2, these functions were named `getXXX()` rather than `onXXX()`. They've [been renamed](https://github.com/GoogleChrome/web-vitals/pull/222) in version 3 to reduce confusion (see [#217](https://github.com/GoogleChrome/web-vitals/pull/217) for details) and will continue to be available using the `getXXX()` until at least version 4. Users are encouraged to switch to the new names, though, for future compatibility.
85
90
86
91
<aname="attribution-build"><a>
87
92
@@ -213,13 +218,15 @@ In other cases, a metric callback may be called more than once:
213
218
- CLS and INP should be reported any time the [page's `visibilityState` changes to hidden](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden).
214
219
- All metrics are reported again (with the above exceptions) after a page is restored from the [back/forward cache](https://web.dev/articles/bfcache).
215
220
216
-
_**Warning:** do not call any of the Web Vitals functions (e.g. `onCLS()`, `onINP()`, `onLCP()`) more than once per page load. Each of these functions creates a `PerformanceObserver` instance and registers event listeners for the lifetime of the page. While the overhead of calling these functions once is negligible, calling them repeatedly on the same page may eventually result in a memory leak._
221
+
> [!WARNING]
222
+
> Do not call any of the Web Vitals functions (e.g. `onCLS()`, `onINP()`, `onLCP()`) more than once per page load. Each of these functions creates a `PerformanceObserver` instance and registers event listeners for the lifetime of the page. While the overhead of calling these functions once is negligible, calling them repeatedly on the same page may eventually result in a memory leak.
217
223
218
224
### Report the value on every change
219
225
220
226
In most cases, you only want the `callback` function to be called when the metric is ready to be reported. However, it is possible to report every change (e.g. each larger layout shift as it happens) by setting `reportAllChanges` to `true` in the optional, [configuration object](#reportopts) (second parameter).
221
227
222
-
_**Important:**`reportAllChanges` only reports when the **metric changes**, not for each **input to the metric**. For example, a new layout shift that does not increase the CLS metric will not be reported even with `reportAllChanges` set to `true` because the CLS metric has not changed. Similarly, for INP, each interaction is not reported even with `reportAllChanges` set to `true`—just when an interaction causes an increase to INP._
228
+
> [!IMPORTANT]
229
+
> `reportAllChanges` only reports when the **metric changes**, not for each **input to the metric**. For example, a new layout shift that does not increase the CLS metric will not be reported even with `reportAllChanges` set to `true` because the CLS metric has not changed. Similarly, for INP, each interaction is not reported even with `reportAllChanges` set to `true`—just when an interaction causes an increase to INP.
223
230
224
231
This can be useful when debugging, but in general using `reportAllChanges` is not needed (or recommended) for measuring these metrics in production.
225
232
@@ -250,7 +257,8 @@ onINP(logDelta);
250
257
onLCP(logDelta);
251
258
```
252
259
253
-
_**Note:** the first time the `callback` function is called, its `value` and `delta` properties will be the same._
260
+
> [!NOTE]
261
+
> The first time the `callback` function is called, its `value` and `delta` properties will be the same.
254
262
255
263
In addition to using the `id` field to group multiple deltas for the same metric, it can also be used to differentiate different metrics reported on the same page. For example, after a back/forward cache restore, a new metric object is created with a new `id` (since back/forward cache restores are considered separate page visits).
256
264
@@ -361,7 +369,8 @@ onINP(sendToGoogleAnalytics);
361
369
onLCP(sendToGoogleAnalytics);
362
370
```
363
371
364
-
_**Note:** this example relies on custom [event parameters](https://support.google.com/analytics/answer/11396839) in Google Analytics 4._
372
+
> [!NOTE]
373
+
> This example relies on custom [event parameters](https://support.google.com/analytics/answer/11396839) in Google Analytics 4.
365
374
366
375
See [Debug performance in the field](https://web.dev/articles/debug-performance-in-the-field) for more information and examples.
_**Note:** see [the Page Lifecycle guide](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#legacy-lifecycle-apis-to-avoid) for an explanation of why `visibilitychange` is recommended over events like `beforeunload` and `unload`._
419
+
> [!NOTE]
420
+
> See [the Page Lifecycle guide](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#legacy-lifecycle-apis-to-avoid) for an explanation of why `visibilitychange` is recommended over events like `beforeunload` and `unload`.
_This interface is deprecated and will be removed in next major release_
588
+
> [!CAUTION]
589
+
> This interface is deprecated and will be removed in the next major release.
579
590
580
591
```ts
581
592
interfaceFIDMetricextendsMetric {
@@ -679,7 +690,8 @@ Calculates the [CLS](https://web.dev/articles/cls) value for the current page an
679
690
680
691
If the `reportAllChanges`[configuration option](#reportopts) is set to `true`, the `callback` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan (Note [not necessarily for every layout shift](#report-the-value-on-every-change)).
681
692
682
-
_**Important:** CLS should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._
693
+
> [!IMPORTANT]
694
+
> CLS should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this).
683
695
684
696
#### `onFCP()`
685
697
@@ -691,15 +703,17 @@ Calculates the [FCP](https://web.dev/articles/fcp) value for the current page an
691
703
692
704
#### `onFID()`
693
705
694
-
_This function is deprecated and will be removed in next major release_
706
+
> [!CAUTION]
707
+
> This function is deprecated and will be removed in the next major release.
695
708
696
709
```ts
697
710
function onFID(callback: (metric:FIDMetric) =>void, opts?:ReportOpts):void;
698
711
```
699
712
700
713
Calculates the [FID](https://web.dev/articles/fid) value for the current page and calls the `callback` function once the value is ready, along with the relevant `first-input` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/docs/Web/API/DOMHighResTimeStamp).
701
714
702
-
_**Important:** since FID is only reported after the user interacts with the page, it's possible that it will not be reported for some page loads._
715
+
> [!IMPORTANT]
716
+
> Since FID is only reported after the user interacts with the page, it's possible that it will not be reported for some page loads.
703
717
704
718
#### `onINP()`
705
719
@@ -713,7 +727,8 @@ A custom `durationThreshold` [configuration option](#reportopts) can optionally
713
727
714
728
If the `reportAllChanges`[configuration option](#reportopts) is set to `true`, the `callback` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan (Note [not necessarily for every interaction](#report-the-value-on-every-change)).
715
729
716
-
_**Important:** INP should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._
730
+
> [!IMPORTANT]
731
+
> INP should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this).
717
732
718
733
#### `onLCP()`
719
734
@@ -751,8 +766,8 @@ onTTFB((metric) => {
751
766
});
752
767
```
753
768
754
-
_**Note:** browsers that do not support `navigation` entries will fall back to
755
-
using `performance.timing` (with the timestamps converted from epoch time to [`DOMHighResTimeStamp`](https://developer.mozilla.org/docs/Web/API/DOMHighResTimeStamp)). This ensures code referencing these values (like in the example above) will work the same in all browsers._
769
+
> [!NOTE]
770
+
> Browsers that do not support `navigation` entries will fall back to using `performance.timing` (with the timestamps converted from epoch time to [`DOMHighResTimeStamp`](https://developer.mozilla.org/docs/Web/API/DOMHighResTimeStamp)). This ensures code referencing these values (like in the example above) will work the same in all browsers.
_**Note:** It's typically not necessary (or recommended) to manually calculate metric value ratings using these thresholds. Use the [`Metric['rating']`](#metric) instead._
786
+
> [!NOTE]
787
+
> It's typically not necessary (or recommended) to manually calculate metric value ratings using these thresholds. Use the [`Metric['rating']`](#metric) instead.
772
788
773
789
### Attribution:
774
790
@@ -853,7 +869,8 @@ interface FCPAttribution {
853
869
854
870
#### `FIDAttribution`
855
871
856
-
_This interface is deprecated and will be removed in next major release_
872
+
> [!CAUTION]
873
+
> This interface is deprecated and will be removed in the next major release.
857
874
858
875
```ts
859
876
interfaceFIDAttribution {
@@ -1091,7 +1108,8 @@ The primary limitation of these APIs is they have no visibility into `<iframe>`
1091
1108
1092
1109
For same-origin iframes, it's possible to use the `web-vitals` library to measure metrics, but it's tricky because it requires the developer to add the library to every frame and `postMessage()` the results to the parent frame for aggregation.
1093
1110
1094
-
_**Note:** given the lack of iframe support, the `onCLS()` function technically measures [DCLS](https://github.com/wicg/layout-instability#cumulative-scores) (Document Cumulative Layout Shift) rather than CLS, if the page includes iframes)._
1111
+
> [!NOTE]
1112
+
> Given the lack of iframe support, the `onCLS()` function technically measures [DCLS](https://github.com/wicg/layout-instability#cumulative-scores) (Document Cumulative Layout Shift) rather than CLS, if the page includes iframes).
0 commit comments