Skip to content

Commit 9bce28a

Browse files
authored
Use fancy md notes (#503)
* Use fancy md notes * prettier * single line
1 parent 4c95f67 commit 9bce28a

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

README.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ The library supports all of the [Core Web Vitals](https://web.dev/articles/vital
4242

4343
- [First Contentful Paint (FCP)](https://web.dev/articles/fcp)
4444
- [Time to First Byte (TTFB)](https://web.dev/articles/ttfb)
45-
- [First Input Delay (FID)](https://web.dev/articles/fid) _Deprecated and will be removed in next major release_
45+
- [First Input Delay (FID)](https://web.dev/articles/fid)
46+
47+
> [!CAUTION]
48+
> FID is deprecated and will be removed in the next major release.
4649
4750
<a name="installation"><a>
4851
<a name="load-the-library"><a>
@@ -63,7 +66,8 @@ You can install this library from npm by running:
6366
npm install web-vitals
6467
```
6568

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.
6771
6872
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.
6973

@@ -81,7 +85,8 @@ onINP(console.log);
8185
onLCP(console.log);
8286
```
8387

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.
8590
8691
<a name="attribution-build"><a>
8792

@@ -213,13 +218,15 @@ In other cases, a metric callback may be called more than once:
213218
- 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).
214219
- All metrics are reported again (with the above exceptions) after a page is restored from the [back/forward cache](https://web.dev/articles/bfcache).
215220

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.
217223
218224
### Report the value on every change
219225

220226
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).
221227

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.
223230
224231
This can be useful when debugging, but in general using `reportAllChanges` is not needed (or recommended) for measuring these metrics in production.
225232

@@ -250,7 +257,8 @@ onINP(logDelta);
250257
onLCP(logDelta);
251258
```
252259

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.
254262
255263
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).
256264

@@ -361,7 +369,8 @@ onINP(sendToGoogleAnalytics);
361369
onLCP(sendToGoogleAnalytics);
362370
```
363371

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.
365374
366375
See [Debug performance in the field](https://web.dev/articles/debug-performance-in-the-field) for more information and examples.
367376

@@ -407,7 +416,8 @@ addEventListener('visibilitychange', () => {
407416
});
408417
```
409418

410-
_**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`.
411421
412422
<a name="bundle-versions"><a>
413423

@@ -575,7 +585,8 @@ interface FCPMetric extends Metric {
575585

576586
##### `FIDMetric`
577587

578-
_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.
579590
580591
```ts
581592
interface FIDMetric extends Metric {
@@ -679,7 +690,8 @@ Calculates the [CLS](https://web.dev/articles/cls) value for the current page an
679690

680691
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)).
681692

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).
683695
684696
#### `onFCP()`
685697

@@ -691,15 +703,17 @@ Calculates the [FCP](https://web.dev/articles/fcp) value for the current page an
691703

692704
#### `onFID()`
693705

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.
695708
696709
```ts
697710
function onFID(callback: (metric: FIDMetric) => void, opts?: ReportOpts): void;
698711
```
699712

700713
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).
701714

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.
703717
704718
#### `onINP()`
705719

@@ -713,7 +727,8 @@ A custom `durationThreshold` [configuration option](#reportopts) can optionally
713727

714728
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)).
715729

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).
717732
718733
#### `onLCP()`
719734

@@ -751,8 +766,8 @@ onTTFB((metric) => {
751766
});
752767
```
753768

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.
756771
757772
### Rating Thresholds:
758773

@@ -768,7 +783,8 @@ console.log(INPThresholds); // [ 200, 500 ]
768783
console.log(LCPThresholds); // [ 2500, 4000 ]
769784
```
770785

771-
_**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.
772788
773789
### Attribution:
774790

@@ -853,7 +869,8 @@ interface FCPAttribution {
853869

854870
#### `FIDAttribution`
855871

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.
857874
858875
```ts
859876
interface FIDAttribution {
@@ -1091,7 +1108,8 @@ The primary limitation of these APIs is they have no visibility into `<iframe>`
10911108

10921109
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.
10931110

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).
10951113
10961114
## Development
10971115

0 commit comments

Comments
 (0)