From 3d6d8e0595b570df705de07620cf6703117d38f5 Mon Sep 17 00:00:00 2001 From: OudomMunint <108245473+OudomMunint@users.noreply.github.com> Date: Thu, 31 Aug 2023 10:31:25 +1000 Subject: [PATCH 1/2] API Boiler plate, Removed smoothscroll.js --- .github/workflows/main.yml | 2 +- API/API.js | 18 ++++++++++++++++++ js/smoothscroll.js | 0 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 API/API.js delete mode 100755 js/smoothscroll.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0a0ca907..80784a68 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,4 +36,4 @@ jobs: - name: Create Release uses: ncipollo/release-action@v1.12.0 with: - tag: v1.5.5.1 \ No newline at end of file + tag: v1.5.5.2 \ No newline at end of file diff --git a/API/API.js b/API/API.js new file mode 100644 index 00000000..5a821071 --- /dev/null +++ b/API/API.js @@ -0,0 +1,18 @@ +const API = { + // Get all proj + async getAllPosts() { + const response = await fetch( + "" + ); + const data = await response.json(); + return data; + }, + // Get proj via id + async getPostById(id) { + const response = await fetch( + `` + ); + const data = await response.json(); + return data; + }, + }; diff --git a/js/smoothscroll.js b/js/smoothscroll.js deleted file mode 100755 index e69de29b..00000000 From 22a47b56ebc02078b59b3619c9bf3e48b4027858 Mon Sep 17 00:00:00 2001 From: OudomMunint Date: Sat, 2 Sep 2023 21:46:09 +1000 Subject: [PATCH 2/2] Installed Web vitals --- node_modules/.package-lock.json | 5 + node_modules/web-vitals/LICENSE | 202 +++ node_modules/web-vitals/README.md | 1284 +++++++++++++++++ node_modules/web-vitals/attribution.d.ts | 16 + node_modules/web-vitals/attribution.js | 18 + node_modules/web-vitals/base.d.ts | 65 + node_modules/web-vitals/base.js | 18 + .../web-vitals/dist/modules/attribution.d.ts | 13 + .../web-vitals/dist/modules/attribution.js | 28 + .../dist/modules/attribution/onCLS.d.ts | 23 + .../dist/modules/attribution/onCLS.js | 72 + .../dist/modules/attribution/onFCP.d.ts | 8 + .../dist/modules/attribution/onFCP.js | 55 + .../dist/modules/attribution/onFID.d.ts | 11 + .../dist/modules/attribution/onFID.js | 43 + .../dist/modules/attribution/onINP.d.ts | 29 + .../dist/modules/attribution/onINP.js | 72 + .../dist/modules/attribution/onLCP.d.ts | 13 + .../dist/modules/attribution/onLCP.js | 82 ++ .../dist/modules/attribution/onTTFB.d.ts | 17 + .../dist/modules/attribution/onTTFB.js | 61 + .../web-vitals/dist/modules/deprecated.d.ts | 35 + .../web-vitals/dist/modules/deprecated.js | 45 + .../web-vitals/dist/modules/index.d.ts | 8 + node_modules/web-vitals/dist/modules/index.js | 23 + .../web-vitals/dist/modules/lib/bfcache.d.ts | 6 + .../web-vitals/dist/modules/lib/bfcache.js | 25 + .../dist/modules/lib/bindReporter.d.ts | 26 + .../dist/modules/lib/bindReporter.js | 45 + .../dist/modules/lib/doubleRAF.d.ts | 1 + .../web-vitals/dist/modules/lib/doubleRAF.js | 18 + .../dist/modules/lib/generateUniqueID.d.ts | 6 + .../dist/modules/lib/generateUniqueID.js | 23 + .../dist/modules/lib/getActivationStart.d.ts | 1 + .../dist/modules/lib/getActivationStart.js | 20 + .../dist/modules/lib/getLoadState.d.ts | 2 + .../dist/modules/lib/getLoadState.js | 47 + .../dist/modules/lib/getNavigationEntry.d.ts | 2 + .../dist/modules/lib/getNavigationEntry.js | 44 + .../dist/modules/lib/getSelector.d.ts | 1 + .../dist/modules/lib/getSelector.js | 48 + .../modules/lib/getVisibilityWatcher.d.ts | 3 + .../dist/modules/lib/getVisibilityWatcher.js | 88 ++ .../dist/modules/lib/initMetric.d.ts | 21 + .../web-vitals/dist/modules/lib/initMetric.js | 48 + .../web-vitals/dist/modules/lib/observe.d.ts | 20 + .../web-vitals/dist/modules/lib/observe.js | 46 + .../web-vitals/dist/modules/lib/onHidden.d.ts | 4 + .../web-vitals/dist/modules/lib/onHidden.js | 26 + .../lib/polyfills/firstInputPolyfill.d.ts | 7 + .../lib/polyfills/firstInputPolyfill.js | 147 ++ .../polyfills/getFirstHiddenTimePolyfill.d.ts | 1 + .../polyfills/getFirstHiddenTimePolyfill.js | 25 + .../polyfills/interactionCountPolyfill.d.ts | 14 + .../lib/polyfills/interactionCountPolyfill.js | 50 + .../web-vitals/dist/modules/lib/runOnce.d.ts | 4 + .../web-vitals/dist/modules/lib/runOnce.js | 24 + .../dist/modules/lib/whenActivated.d.ts | 1 + .../dist/modules/lib/whenActivated.js | 23 + .../web-vitals/dist/modules/onCLS.d.ts | 25 + node_modules/web-vitals/dist/modules/onCLS.js | 108 ++ .../web-vitals/dist/modules/onFCP.d.ts | 10 + node_modules/web-vitals/dist/modules/onFCP.js | 71 + .../web-vitals/dist/modules/onFID.d.ts | 13 + node_modules/web-vitals/dist/modules/onFID.js | 87 ++ .../web-vitals/dist/modules/onINP.d.ts | 31 + node_modules/web-vitals/dist/modules/onINP.js | 191 +++ .../web-vitals/dist/modules/onLCP.d.ts | 15 + node_modules/web-vitals/dist/modules/onLCP.js | 95 ++ .../web-vitals/dist/modules/onTTFB.d.ts | 19 + .../web-vitals/dist/modules/onTTFB.js | 88 ++ .../web-vitals/dist/modules/polyfill.d.ts | 1 + .../web-vitals/dist/modules/polyfill.js | 25 + .../web-vitals/dist/modules/types.d.ts | 62 + node_modules/web-vitals/dist/modules/types.js | 23 + .../web-vitals/dist/modules/types/base.d.ts | 107 ++ .../web-vitals/dist/modules/types/base.js | 16 + .../web-vitals/dist/modules/types/cls.d.ts | 67 + .../web-vitals/dist/modules/types/cls.js | 16 + .../web-vitals/dist/modules/types/fcp.d.ts | 59 + .../web-vitals/dist/modules/types/fcp.js | 16 + .../web-vitals/dist/modules/types/fid.d.ts | 60 + .../web-vitals/dist/modules/types/fid.js | 16 + .../web-vitals/dist/modules/types/inp.d.ts | 59 + .../web-vitals/dist/modules/types/inp.js | 16 + .../web-vitals/dist/modules/types/lcp.d.ts | 82 ++ .../web-vitals/dist/modules/types/lcp.js | 16 + .../dist/modules/types/polyfills.d.ts | 7 + .../dist/modules/types/polyfills.js | 16 + .../web-vitals/dist/modules/types/ttfb.d.ts | 60 + .../web-vitals/dist/modules/types/ttfb.js | 16 + node_modules/web-vitals/dist/polyfill.js | 1 + .../dist/web-vitals.attribution.iife.js | 1 + .../web-vitals/dist/web-vitals.attribution.js | 1 + .../dist/web-vitals.attribution.umd.cjs | 1 + .../web-vitals/dist/web-vitals.base.iife.js | 1 + .../web-vitals/dist/web-vitals.base.js | 1 + .../web-vitals/dist/web-vitals.base.umd.cjs | 1 + .../web-vitals/dist/web-vitals.iife.js | 1 + node_modules/web-vitals/dist/web-vitals.js | 1 + .../web-vitals/dist/web-vitals.umd.cjs | 1 + node_modules/web-vitals/package.json | 186 +++ node_modules/web-vitals/src/attribution.ts | 31 + .../web-vitals/src/attribution/onCLS.ts | 90 ++ .../web-vitals/src/attribution/onFCP.ts | 73 + .../web-vitals/src/attribution/onFID.ts | 59 + .../web-vitals/src/attribution/onINP.ts | 91 ++ .../web-vitals/src/attribution/onLCP.ts | 114 ++ .../web-vitals/src/attribution/onTTFB.ts | 88 ++ node_modules/web-vitals/src/deprecated.ts | 64 + node_modules/web-vitals/src/index.ts | 25 + node_modules/web-vitals/src/lib/bfcache.ts | 36 + .../web-vitals/src/lib/bindReporter.ts | 58 + node_modules/web-vitals/src/lib/doubleRAF.ts | 19 + .../web-vitals/src/lib/generateUniqueID.ts | 24 + .../web-vitals/src/lib/getActivationStart.ts | 22 + .../web-vitals/src/lib/getLoadState.ts | 51 + .../web-vitals/src/lib/getNavigationEntry.ts | 60 + .../web-vitals/src/lib/getSelector.ts | 48 + .../src/lib/getVisibilityWatcher.ts | 96 ++ node_modules/web-vitals/src/lib/initMetric.ts | 57 + node_modules/web-vitals/src/lib/observe.ts | 70 + node_modules/web-vitals/src/lib/onHidden.ts | 31 + .../src/lib/polyfills/firstInputPolyfill.ts | 174 +++ .../polyfills/getFirstHiddenTimePolyfill.ts | 29 + .../lib/polyfills/interactionCountPolyfill.ts | 63 + node_modules/web-vitals/src/lib/runOnce.ts | 29 + .../web-vitals/src/lib/whenActivated.ts | 23 + node_modules/web-vitals/src/onCLS.ts | 140 ++ node_modules/web-vitals/src/onFCP.ts | 97 ++ node_modules/web-vitals/src/onFID.ts | 131 ++ node_modules/web-vitals/src/onINP.ts | 256 ++++ node_modules/web-vitals/src/onLCP.ts | 127 ++ node_modules/web-vitals/src/onTTFB.ts | 112 ++ node_modules/web-vitals/src/polyfill.ts | 30 + node_modules/web-vitals/src/types.ts | 112 ++ node_modules/web-vitals/src/types/base.ts | 158 ++ node_modules/web-vitals/src/types/cls.ts | 88 ++ node_modules/web-vitals/src/types/fcp.ts | 80 + node_modules/web-vitals/src/types/fid.ts | 81 ++ node_modules/web-vitals/src/types/inp.ts | 80 + node_modules/web-vitals/src/types/lcp.ts | 103 ++ .../web-vitals/src/types/polyfills.ts | 37 + node_modules/web-vitals/src/types/ttfb.ts | 81 ++ package-lock.json | 8 +- package.json | 3 +- 146 files changed, 8049 insertions(+), 2 deletions(-) create mode 100644 node_modules/web-vitals/LICENSE create mode 100644 node_modules/web-vitals/README.md create mode 100644 node_modules/web-vitals/attribution.d.ts create mode 100644 node_modules/web-vitals/attribution.js create mode 100644 node_modules/web-vitals/base.d.ts create mode 100644 node_modules/web-vitals/base.js create mode 100644 node_modules/web-vitals/dist/modules/attribution.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onCLS.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onCLS.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onFCP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onFCP.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onFID.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onFID.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onINP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onINP.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onLCP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onLCP.js create mode 100644 node_modules/web-vitals/dist/modules/attribution/onTTFB.d.ts create mode 100644 node_modules/web-vitals/dist/modules/attribution/onTTFB.js create mode 100644 node_modules/web-vitals/dist/modules/deprecated.d.ts create mode 100644 node_modules/web-vitals/dist/modules/deprecated.js create mode 100644 node_modules/web-vitals/dist/modules/index.d.ts create mode 100644 node_modules/web-vitals/dist/modules/index.js create mode 100644 node_modules/web-vitals/dist/modules/lib/bfcache.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/bfcache.js create mode 100644 node_modules/web-vitals/dist/modules/lib/bindReporter.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/bindReporter.js create mode 100644 node_modules/web-vitals/dist/modules/lib/doubleRAF.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/doubleRAF.js create mode 100644 node_modules/web-vitals/dist/modules/lib/generateUniqueID.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/generateUniqueID.js create mode 100644 node_modules/web-vitals/dist/modules/lib/getActivationStart.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/getActivationStart.js create mode 100644 node_modules/web-vitals/dist/modules/lib/getLoadState.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/getLoadState.js create mode 100644 node_modules/web-vitals/dist/modules/lib/getNavigationEntry.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/getNavigationEntry.js create mode 100644 node_modules/web-vitals/dist/modules/lib/getSelector.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/getSelector.js create mode 100644 node_modules/web-vitals/dist/modules/lib/getVisibilityWatcher.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/getVisibilityWatcher.js create mode 100644 node_modules/web-vitals/dist/modules/lib/initMetric.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/initMetric.js create mode 100644 node_modules/web-vitals/dist/modules/lib/observe.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/observe.js create mode 100644 node_modules/web-vitals/dist/modules/lib/onHidden.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/onHidden.js create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/firstInputPolyfill.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/firstInputPolyfill.js create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/getFirstHiddenTimePolyfill.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/getFirstHiddenTimePolyfill.js create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/interactionCountPolyfill.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/polyfills/interactionCountPolyfill.js create mode 100644 node_modules/web-vitals/dist/modules/lib/runOnce.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/runOnce.js create mode 100644 node_modules/web-vitals/dist/modules/lib/whenActivated.d.ts create mode 100644 node_modules/web-vitals/dist/modules/lib/whenActivated.js create mode 100644 node_modules/web-vitals/dist/modules/onCLS.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onCLS.js create mode 100644 node_modules/web-vitals/dist/modules/onFCP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onFCP.js create mode 100644 node_modules/web-vitals/dist/modules/onFID.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onFID.js create mode 100644 node_modules/web-vitals/dist/modules/onINP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onINP.js create mode 100644 node_modules/web-vitals/dist/modules/onLCP.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onLCP.js create mode 100644 node_modules/web-vitals/dist/modules/onTTFB.d.ts create mode 100644 node_modules/web-vitals/dist/modules/onTTFB.js create mode 100644 node_modules/web-vitals/dist/modules/polyfill.d.ts create mode 100644 node_modules/web-vitals/dist/modules/polyfill.js create mode 100644 node_modules/web-vitals/dist/modules/types.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types.js create mode 100644 node_modules/web-vitals/dist/modules/types/base.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/base.js create mode 100644 node_modules/web-vitals/dist/modules/types/cls.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/cls.js create mode 100644 node_modules/web-vitals/dist/modules/types/fcp.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/fcp.js create mode 100644 node_modules/web-vitals/dist/modules/types/fid.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/fid.js create mode 100644 node_modules/web-vitals/dist/modules/types/inp.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/inp.js create mode 100644 node_modules/web-vitals/dist/modules/types/lcp.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/lcp.js create mode 100644 node_modules/web-vitals/dist/modules/types/polyfills.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/polyfills.js create mode 100644 node_modules/web-vitals/dist/modules/types/ttfb.d.ts create mode 100644 node_modules/web-vitals/dist/modules/types/ttfb.js create mode 100644 node_modules/web-vitals/dist/polyfill.js create mode 100644 node_modules/web-vitals/dist/web-vitals.attribution.iife.js create mode 100644 node_modules/web-vitals/dist/web-vitals.attribution.js create mode 100644 node_modules/web-vitals/dist/web-vitals.attribution.umd.cjs create mode 100644 node_modules/web-vitals/dist/web-vitals.base.iife.js create mode 100644 node_modules/web-vitals/dist/web-vitals.base.js create mode 100644 node_modules/web-vitals/dist/web-vitals.base.umd.cjs create mode 100644 node_modules/web-vitals/dist/web-vitals.iife.js create mode 100644 node_modules/web-vitals/dist/web-vitals.js create mode 100644 node_modules/web-vitals/dist/web-vitals.umd.cjs create mode 100644 node_modules/web-vitals/package.json create mode 100644 node_modules/web-vitals/src/attribution.ts create mode 100644 node_modules/web-vitals/src/attribution/onCLS.ts create mode 100644 node_modules/web-vitals/src/attribution/onFCP.ts create mode 100644 node_modules/web-vitals/src/attribution/onFID.ts create mode 100644 node_modules/web-vitals/src/attribution/onINP.ts create mode 100644 node_modules/web-vitals/src/attribution/onLCP.ts create mode 100644 node_modules/web-vitals/src/attribution/onTTFB.ts create mode 100644 node_modules/web-vitals/src/deprecated.ts create mode 100644 node_modules/web-vitals/src/index.ts create mode 100644 node_modules/web-vitals/src/lib/bfcache.ts create mode 100644 node_modules/web-vitals/src/lib/bindReporter.ts create mode 100644 node_modules/web-vitals/src/lib/doubleRAF.ts create mode 100644 node_modules/web-vitals/src/lib/generateUniqueID.ts create mode 100644 node_modules/web-vitals/src/lib/getActivationStart.ts create mode 100644 node_modules/web-vitals/src/lib/getLoadState.ts create mode 100644 node_modules/web-vitals/src/lib/getNavigationEntry.ts create mode 100644 node_modules/web-vitals/src/lib/getSelector.ts create mode 100644 node_modules/web-vitals/src/lib/getVisibilityWatcher.ts create mode 100644 node_modules/web-vitals/src/lib/initMetric.ts create mode 100644 node_modules/web-vitals/src/lib/observe.ts create mode 100644 node_modules/web-vitals/src/lib/onHidden.ts create mode 100644 node_modules/web-vitals/src/lib/polyfills/firstInputPolyfill.ts create mode 100644 node_modules/web-vitals/src/lib/polyfills/getFirstHiddenTimePolyfill.ts create mode 100644 node_modules/web-vitals/src/lib/polyfills/interactionCountPolyfill.ts create mode 100644 node_modules/web-vitals/src/lib/runOnce.ts create mode 100644 node_modules/web-vitals/src/lib/whenActivated.ts create mode 100644 node_modules/web-vitals/src/onCLS.ts create mode 100644 node_modules/web-vitals/src/onFCP.ts create mode 100644 node_modules/web-vitals/src/onFID.ts create mode 100644 node_modules/web-vitals/src/onINP.ts create mode 100644 node_modules/web-vitals/src/onLCP.ts create mode 100644 node_modules/web-vitals/src/onTTFB.ts create mode 100644 node_modules/web-vitals/src/polyfill.ts create mode 100644 node_modules/web-vitals/src/types.ts create mode 100644 node_modules/web-vitals/src/types/base.ts create mode 100644 node_modules/web-vitals/src/types/cls.ts create mode 100644 node_modules/web-vitals/src/types/fcp.ts create mode 100644 node_modules/web-vitals/src/types/fid.ts create mode 100644 node_modules/web-vitals/src/types/inp.ts create mode 100644 node_modules/web-vitals/src/types/lcp.ts create mode 100644 node_modules/web-vitals/src/types/polyfills.ts create mode 100644 node_modules/web-vitals/src/types/ttfb.ts diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 6dabd0c8..82bb00a7 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -6241,6 +6241,11 @@ "node": ">=0.10.0" } }, + "node_modules/web-vitals": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-3.4.0.tgz", + "integrity": "sha512-n9fZ5/bG1oeDkyxLWyep0eahrNcPDF6bFqoyispt7xkW0xhDzpUBTgyDKqWDi1twT0MgH4HvvqzpUyh0ZxZV4A==" + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/node_modules/web-vitals/LICENSE b/node_modules/web-vitals/LICENSE new file mode 100644 index 00000000..618d629b --- /dev/null +++ b/node_modules/web-vitals/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2020 Google LLC + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/node_modules/web-vitals/README.md b/node_modules/web-vitals/README.md new file mode 100644 index 00000000..aeb97252 --- /dev/null +++ b/node_modules/web-vitals/README.md @@ -0,0 +1,1284 @@ +# `web-vitals` + +- [Overview](#overview) +- [Install and load the library](#installation) + - [From npm](#import-web-vitals-from-npm) + - [From a CDN](#load-web-vitals-from-a-cdn) +- [Usage](#usage) + - [Basic usage](#basic-usage) + - [Report the value on every change](#report-the-value-on-every-change) + - [Report only the delta of changes](#report-only-the-delta-of-changes) + - [Send the results to an analytics endpoint](#send-the-results-to-an-analytics-endpoint) + - [Send the results to Google Analytics](#send-the-results-to-google-analytics) + - [Send the results to Google Tag Manager](#send-the-results-to-google-tag-manager) + - [Send attribution data](#send-attribution-data) + - [Batch multiple reports together](#batch-multiple-reports-together) +- [Build options](#build-options) + - [Which build is right for you?](#which-build-is-right-for-you) + - [How the polyfill works](#how-the-polyfill-works) +- [API](#api) + - [Types](#types) + - [Functions](#functions) + - [Rating Thresholds](#rating-thresholds) + - [Attribution](#attribution) +- [Browser Support](#browser-support) +- [Limitations](#limitations) +- [Development](#development) +- [Integrations](#integrations) +- [License](#license) + +## Overview + +The `web-vitals` library is a tiny (~1.5K, brotli'd), modular library for measuring all the [Web Vitals](https://web.dev/vitals/) metrics on real users, in a way that accurately matches how they're measured by Chrome and reported to other Google tools (e.g. [Chrome User Experience Report](https://developers.google.com/web/tools/chrome-user-experience-report), [Page Speed Insights](https://developers.google.com/speed/pagespeed/insights/), [Search Console's Speed Report](https://webmasters.googleblog.com/2019/11/search-console-speed-report.html)). + +The library supports all of the [Core Web Vitals](https://web.dev/vitals/#core-web-vitals) as well as a number of other metrics that are useful in diagnosing [real-user](https://web.dev/user-centric-performance-metrics/) performance issues. + +### Core Web Vitals + +- [Cumulative Layout Shift (CLS)](https://web.dev/cls/) +- [First Input Delay (FID)](https://web.dev/fid/) +- [Largest Contentful Paint (LCP)](https://web.dev/lcp/) + +### Other metrics + +- [Interaction to next Paint (INP)](https://web.dev/inp/) +- [First Contentful Paint (FCP)](https://web.dev/fcp/) +- [Time to First Byte (TTFB)](https://web.dev/ttfb/) + + + + +## Install and load the library + + + +The `web-vitals` library uses the `buffered` flag for [PerformanceObserver](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/observe), allowing it to access performance entries that occurred before the library was loaded. + +This means you do not need to load this library early in order to get accurate performance data. In general, this library should be deferred until after other user-impacting code has loaded. + +### From npm + +You can install this library from npm by running: + +```sh +npm install web-vitals +``` + +_**Note:** If you're not using npm, you can still load `web-vitals` via ` + + + ... + + +``` + +It's important that the code is inlined directly into the HTML. _Do not link to an external script file, as that will negatively affect performance:_ + +```html + + + + + +``` + +Also note that the code _must_ go in the `` of your pages in order to work. See [how the polyfill works](#how-the-polyfill-works) for more details. + +_**Tip:** while it's certainly possible to inline the code in `dist/polyfill.js` by copy and pasting it directly into your templates, it's better to automate this process in a build step—otherwise you risk the "base" and the "polyfill" scripts getting out of sync when new versions are released._ + + + +### From a CDN + +The recommended way to use the `web-vitals` package is to install it from npm and integrate it into your build process. However, if you're not using npm, it's still possible to use `web-vitals` by requesting it from a CDN that serves npm package files. + +The following examples show how to load `web-vitals` from [unpkg.com](https://unpkg.com): + +_**Important!** The [unpkg.com](https://unpkg.com) CDN is shown here for example purposes only. `unpkg.com` is not affiliated with Google, and there are no guarantees that the URLs shown in these examples will continue to work in the future._ + +**Load the "standard" build** _(using a module script)_ + +```html + + +``` + +**Load the "standard" build** _(using a classic script)_ + +```html + +``` + +**Load the "attribution" build** _(using a module script)_ + +```html + + +``` + +**Load the "attribution" build** _(using a classic script)_ + +```html + +``` + +## Usage + +### Basic usage + +Each of the Web Vitals metrics is exposed as a single function that takes a `callback` function that will be called any time the metric value is available and ready to be reported. + +The following example measures each of the Core Web Vitals metrics and logs the result to the console once its value is ready to report. + +_(The examples below import the "standard" build, but they will work with the "attribution" build as well.)_ + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +onCLS(console.log); +onFID(console.log); +onLCP(console.log); +``` + +Note that some of these metrics will not report until the user has interacted with the page, switched tabs, or the page starts to unload. If you don't see the values logged to the console immediately, try reloading the page (with [preserve log](https://developer.chrome.com/docs/devtools/console/reference/#persist) enabled) or switching tabs and then switching back. + +Also, in some cases a metric callback may never be called: + +- FID is not reported if the user never interacts with the page. +- CLS, FCP, FID, and LCP are not reported if the page was loaded in the background. + +In other cases, a metric callback may be called more than once: + +- CLS should be reported any time the [page's `visibilityState` changes to hidden](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden). +- All metrics are reported again (with the above exceptions) after a page is restored from the [back/forward cache](https://web.dev/bfcache/). + +_**Warning:** do not call any of the Web Vitals functions (e.g. `onCLS()`, `onFID()`, `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._ + +### Report the value on every change + +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 layout shift as it happens) by setting `reportAllChanges` to `true` in the optional, [configuration object](#reportopts) (second parameter). + +This can be useful when debugging, but in general using `reportAllChanges` is not needed (or recommended) for measuring these metrics in production. + +```js +import {onCLS} from 'web-vitals'; + +// Logs CLS as the value changes. +onCLS(console.log, {reportAllChanges: true}); +``` + +### Report only the delta of changes + +Some analytics providers allow you to update the value of a metric, even after you've already sent it to their servers (overwriting the previously-sent value with the same `id`). + +Other analytics providers, however, do not allow this, so instead of reporting the new value, you need to report only the delta (the difference between the current value and the last-reported value). You can then compute the total value by summing all metric deltas sent with the same ID. + +The following example shows how to use the `id` and `delta` properties: + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +function logDelta({name, id, delta}) { + console.log(`${name} matching ID ${id} changed by ${delta}`); +} + +onCLS(logDelta); +onFID(logDelta); +onLCP(logDelta); +``` + +_**Note:** the first time the `callback` function is called, its `value` and `delta` properties will be the same._ + +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). + +### Send the results to an analytics endpoint + +The following example measures each of the Core Web Vitals metrics and reports them to a hypothetical `/analytics` endpoint, as soon as each is ready to be sent. + +The `sendToAnalytics()` function uses the [`navigator.sendBeacon()`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) method (if available), but falls back to the [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API when not. + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +function sendToAnalytics(metric) { + // Replace with whatever serialization method you prefer. + // Note: JSON.stringify will likely include more data than you need. + const body = JSON.stringify(metric); + + // Use `navigator.sendBeacon()` if available, falling back to `fetch()`. + (navigator.sendBeacon && navigator.sendBeacon('/analytics', body)) || + fetch('/analytics', {body, method: 'POST', keepalive: true}); +} + +onCLS(sendToAnalytics); +onFID(sendToAnalytics); +onLCP(sendToAnalytics); +``` + +### Send the results to Google Analytics + +Google Analytics does not support reporting metric distributions in any of its built-in reports; however, if you set a unique dimension value (in this case, the metric `id`, as shown in the examples below) on every metric instance that you send to Google Analytics, you can create a report yourself using the [Google Analytics Reporting API](https://developers.google.com/analytics/devguides/reporting) and any data visualization library you choose. + +As an example of this, the [Web Vitals Report](https://github.com/GoogleChromeLabs/web-vitals-report) is a free and open-source tool you can use to create visualizations of the Web Vitals data that you've sent to Google Analytics. + +[![web-vitals-report](https://user-images.githubusercontent.com/326742/101584324-3f9a0900-3992-11eb-8f2d-182f302fb67b.png)](https://github.com/GoogleChromeLabs/web-vitals-report) + +In order to use the [Web Vitals Report](https://github.com/GoogleChromeLabs/web-vitals-report) (or build your own custom reports using the API) you need to send your data to Google Analytics following one of the examples outlined below: + +#### Using `analytics.js` + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +function sendToGoogleAnalytics({name, delta, id}) { + // Assumes the global `ga()` function exists, see: + // https://developers.google.com/analytics/devguides/collection/analyticsjs + ga('send', 'event', { + eventCategory: 'Web Vitals', + eventAction: name, + // The `id` value will be unique to the current page load. When sending + // multiple values from the same page (e.g. for CLS), Google Analytics can + // compute a total by grouping on this ID (note: requires `eventLabel` to + // be a dimension in your report). + eventLabel: id, + // Google Analytics metrics must be integers, so the value is rounded. + // For CLS the value is first multiplied by 1000 for greater precision + // (note: increase the multiplier for greater precision if needed). + eventValue: Math.round(name === 'CLS' ? delta * 1000 : delta), + // Use a non-interaction event to avoid affecting bounce rate. + nonInteraction: true, + // Use `sendBeacon()` if the browser supports it. + transport: 'beacon', + + // OPTIONAL: any additional attribution params here. + // See: https://web.dev/debug-performance-in-the-field/ + // dimension1: '...', + // dimension2: '...', + // ... + }); +} + +onCLS(sendToGoogleAnalytics); +onFID(sendToGoogleAnalytics); +onLCP(sendToGoogleAnalytics); +``` + +#### Using `gtag.js` (Universal Analytics) + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +function sendToGoogleAnalytics({name, delta, id}) { + // Assumes the global `gtag()` function exists, see: + // https://developers.google.com/analytics/devguides/collection/gtagjs + gtag('event', name, { + event_category: 'Web Vitals', + // The `id` value will be unique to the current page load. When sending + // multiple values from the same page (e.g. for CLS), Google Analytics can + // compute a total by grouping on this ID (note: requires `eventLabel` to + // be a dimension in your report). + event_label: id, + // Google Analytics metrics must be integers, so the value is rounded. + // For CLS the value is first multiplied by 1000 for greater precision + // (note: increase the multiplier for greater precision if needed). + value: Math.round(name === 'CLS' ? delta * 1000 : delta), + // Use a non-interaction event to avoid affecting bounce rate. + non_interaction: true, + + // OPTIONAL: any additional attribution params here. + // See: https://web.dev/debug-performance-in-the-field/ + // dimension1: '...', + // dimension2: '...', + // ... + }); +} + +onCLS(sendToGoogleAnalytics); +onFID(sendToGoogleAnalytics); +onLCP(sendToGoogleAnalytics); +``` + +#### Using `gtag.js` (Google Analytics 4) + +[Google Analytics 4](https://support.google.com/analytics/answer/10089681) introduces a new Event model allowing custom parameters instead of a fixed category, action, and label. It also supports non-integer values, making it easier to measure Web Vitals metrics compared to previous versions. + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +function sendToGoogleAnalytics({name, delta, value, id}) { + // Assumes the global `gtag()` function exists, see: + // https://developers.google.com/analytics/devguides/collection/ga4 + gtag('event', name, { + // Built-in params: + value: delta, // Use `delta` so the value can be summed. + // Custom params: + metric_id: id, // Needed to aggregate events. + metric_value: value, // Optional. + metric_delta: delta, // Optional. + + // OPTIONAL: any additional params or debug info here. + // See: https://web.dev/debug-performance-in-the-field/ + // metric_rating: 'good' | 'needs-improvement' | 'poor', + // debug_info: '...', + // ... + }); +} + +onCLS(sendToGoogleAnalytics); +onFID(sendToGoogleAnalytics); +onLCP(sendToGoogleAnalytics); +``` + +### Send the results to Google Tag Manager + +The recommended way to measure Web Vitals metrics with Google Tag Manager is using the [Core Web Vitals](https://www.simoahava.com/custom-templates/core-web-vitals/) custom template tag created and maintained by [Simo Ahava](https://www.simoahava.com/). + +For full installation and usage instructions, see Simo's post: [Track Core Web Vitals in GA4 with Google Tag Manager](https://www.simoahava.com/analytics/track-core-web-vitals-in-ga4-with-google-tag-manager/). + +### Send attribution data + +When using the [attribution build](#attribution-build), you can send additional data to help you debug _why_ the metric values are they way they are. + +This example sends an additional `debug_target` param to Google Analytics, corresponding to the element most associated with each metric. + +```js +import {onCLS, onFID, onLCP} from 'web-vitals/attribution'; + +function sendToGoogleAnalytics({name, delta, value, id, attribution}) { + const eventParams = { + // Built-in params: + value: delta, // Use `delta` so the value can be summed. + // Custom params: + metric_id: id, // Needed to aggregate events. + metric_value: value, // Optional. + metric_delta: delta, // Optional. + }; + + switch (name) { + case 'CLS': + eventParams.debug_target = attribution.largestShiftTarget; + break; + case 'FID': + eventParams.debug_target = attribution.eventTarget; + break; + case 'LCP': + eventParams.debug_target = attribution.element; + break; + } + + // Assumes the global `gtag()` function exists, see: + // https://developers.google.com/analytics/devguides/collection/ga4 + gtag('event', name, eventParams); +} + +onCLS(sendToGoogleAnalytics); +onFID(sendToGoogleAnalytics); +onLCP(sendToGoogleAnalytics); +``` + +_**Note:** this example relies on custom [event parameters](https://support.google.com/analytics/answer/11396839) in Google Analytics 4. For Universal Analytics the attribution data should be set using a [custom dimension](https://support.google.com/analytics/answer/2709828) rather than `debug_target` as shown above._ + +See [Debug performance in the field](https://web.dev/debug-performance-in-the-field/) for more information and examples. + +### Batch multiple reports together + +Rather than reporting each individual Web Vitals metric separately, you can minimize your network usage by batching multiple metric reports together in a single network request. + +However, since not all Web Vitals metrics become available at the same time, and since not all metrics are reported on every page, you cannot simply defer reporting until all metrics are available. + +Instead, you should keep a queue of all metrics that were reported and flush the queue whenever the page is backgrounded or unloaded: + +```js +import {onCLS, onFID, onLCP} from 'web-vitals'; + +const queue = new Set(); +function addToQueue(metric) { + queue.add(metric); +} + +function flushQueue() { + if (queue.size > 0) { + // Replace with whatever serialization method you prefer. + // Note: JSON.stringify will likely include more data than you need. + const body = JSON.stringify([...queue]); + + // Use `navigator.sendBeacon()` if available, falling back to `fetch()`. + (navigator.sendBeacon && navigator.sendBeacon('/analytics', body)) || + fetch('/analytics', {body, method: 'POST', keepalive: true}); + + queue.clear(); + } +} + +onCLS(addToQueue); +onFID(addToQueue); +onLCP(addToQueue); + +// Report all available metrics whenever the page is backgrounded or unloaded. +addEventListener('visibilitychange', () => { + if (document.visibilityState === 'hidden') { + flushQueue(); + } +}); + +// NOTE: Safari does not reliably fire the `visibilitychange` event when the +// page is being unloaded. If Safari support is needed, you should also flush +// the queue in the `pagehide` event. +addEventListener('pagehide', flushQueue); +``` + +_**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` and `pagehide` are recommended over events like `beforeunload` and `unload`._ + + + +## Build options + +The `web-vitals` package includes builds for the "standard", "attribution", and "base+polyfill" ([deprecated](https://github.com/GoogleChrome/web-vitals/issues/238)) builds, as well as different formats of each to allow developers to choose the format that best meets their needs or integrates with their architecture. + +The following table lists all the builds distributed with the `web-vitals` package on npm. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Filename (all within dist/*) + ExportDescription
web-vitals.jspkg.module +

An ES module bundle of all metric functions, without any attribution features.

+ This is the "standard" build and is the simplest way to consume this library out of the box. +
web-vitals.umd.cjspgk.main + A UMD version of the web-vitals.js bundle (exposed on the window.webVitals.* namespace). +
web-vitals.iife.js-- + An IIFE version of the web-vitals.js bundle (exposed on the window.webVitals.* namespace). +
web-vitals.attribution.js-- + An ES module version of all metric functions that includes attribution features. +
web-vitals.attribution.umd.cjs-- + A UMD version of the web-vitals.attribution.js build (exposed on the window.webVitals.* namespace). +
web-vitals.attribution.iife.js-- + An IIFE version of the web-vitals.attribution.js build (exposed on the window.webVitals.* namespace). +
web-vitals.base.js-- +

This build has been deprecated.

+

An ES module bundle containing just the "base" part of the "base+polyfill" version.

+ Use this bundle if (and only if) you've also added the polyfill.js script to the <head> of your pages. See how to use the polyfill for more details. +
web-vitals.base.umd.cjs-- +

This build has been deprecated.

+

A UMD version of the web-vitals.base.js bundle (exposed on the window.webVitals.* namespace).

+
web-vitals.base.iife.js-- +

This build has been deprecated.

+

An IIFE version of the web-vitals.base.js bundle (exposed on the window.webVitals.* namespace).

+
polyfill.js-- +

This build has been deprecated.

+

The "polyfill" part of the "base+polyfill" version. This script should be used with either web-vitals.base.js, web-vitals.base.umd.cjs, or web-vitals.base.iife.js (it will not work with any script that doesn't have "base" in the filename).

+ See how to use the polyfill for more details. +
+ +
+ +### Which build is right for you? + +Most developers will generally want to use "standard" build (via either the ES module or UMD version, depending on your bundler/build system), as it's the easiest to use out of the box and integrate into existing tools. + +However, if you'd lke to collect additional debug information to help you diagnose performance bottlenecks based on real-user issues, use the ["attribution" build](#attribution-build). + +For guidance on how to collect and use real-user data to debug performance issues, see [Debug performance in the field](https://web.dev/debug-performance-in-the-field/). + +### How the polyfill works + +_**⚠️ Warning ⚠️** the "base+polyfill" build is deprecated. See [#238](https://github.com/GoogleChrome/web-vitals/issues/238) for details._ + +The `polyfill.js` script adds event listeners (to track FID cross-browser), and it records initial page visibility state as well as the timestamp of the first visibility change to hidden (to improve the accuracy of CLS, FCP, LCP, and FID). It also polyfills the [Navigation Timing API Level 2](https://www.w3.org/TR/navigation-timing-2/) in browsers that only support the original (now deprecated) [Navigation Timing API](https://www.w3.org/TR/navigation-timing/). + +In order for the polyfill to work properly, the script must be the first script added to the page, and it must run before the browser renders any content to the screen. This is why it needs to be added to the `` of the document. + +The "standard" build of the `web-vitals` library includes some of the same logic found in `polyfill.js`. To avoid duplicating that code when using the "base+polyfill" build, the `web-vitals.base.js` bundle does not include any polyfill logic, instead it coordinates with the code in `polyfill.js`, which is why the two scripts must be used together. + +## API + +### Types: + +#### `Metric` + +```ts +interface Metric { + /** + * The name of the metric (in acronym form). + */ + name: 'CLS' | 'FCP' | 'FID' | 'INP' | 'LCP' | 'TTFB'; + + /** + * The current value of the metric. + */ + value: number; + + /** + * The rating as to whether the metric value is within the "good", + * "needs improvement", or "poor" thresholds of the metric. + */ + rating: 'good' | 'needs-improvement' | 'poor'; + + /** + * The delta between the current value and the last-reported value. + * On the first report, `delta` and `value` will always be the same. + */ + delta: number; + + /** + * A unique ID representing this particular metric instance. This ID can + * be used by an analytics tool to dedupe multiple values sent for the same + * metric instance, or to group multiple deltas together and calculate a + * total. It can also be used to differentiate multiple different metric + * instances sent from the same page, which can happen if the page is + * restored from the back/forward cache (in that case new metrics object + * get created). + */ + id: string; + + /** + * Any performance entries relevant to the metric value calculation. + * The array may also be empty if the metric value was not based on any + * entries (e.g. a CLS value of 0 given no layout shifts). + */ + entries: ( + | PerformanceEntry + | LayoutShift + | FirstInputPolyfillEntry + | NavigationTimingPolyfillEntry + )[]; + + /** + * The type of navigation. + * + * This will be the value returned by the Navigation Timing API (or + * `undefined` if the browser doesn't support that API), with the following + * exceptions: + * - 'back-forward-cache': for pages that are restored from the bfcache. + * - 'prerender': for pages that were prerendered. + * - 'restore': for pages that were discarded by the browser and then + * restored by the user. + */ + navigationType: + | 'navigate' + | 'reload' + | 'back-forward' + | 'back-forward-cache' + | 'prerender' + | 'restore'; +} +``` + +Metric-specific subclasses: + +- [`CLSMetric`](/src/types/cls.ts#:~:text=interface%20CLSMetric) +- [`FCPMetric`](/src/types/fcp.ts#:~:text=interface%20FCPMetric) +- [`FIDMetric`](/src/types/fid.ts#:~:text=interface%20FIDMetric) +- [`INPMetric`](/src/types/inp.ts#:~:text=interface%20INPMetric) +- [`LCPMetric`](/src/types/lcp.ts#:~:text=interface%20LCPMetric) +- [`TTFBMetric`](/src/types/ttfb.ts#:~:text=interface%20TTFBMetric) + +#### `MetricWithAttribution` + +See the [attribution build](#attribution-build) section for details on how to use this feature. + +```ts +interface MetricWithAttribution extends Metric { + /** + * An object containing potentially-helpful debugging information that + * can be sent along with the metric value for the current page visit in + * order to help identify issues happening to real-users in the field. + */ + attribution: {[key: string]: unknown}; +} +``` + +Metric-specific subclasses: + +- [`CLSMetricWithAttribution`](/src/types/cls.ts#:~:text=interface%20CLSMetricWithAttribution) +- [`FCPMetricWithAttribution`](/src/types/fcp.ts#:~:text=interface%20FCPMetricWithAttribution) +- [`FIDMetricWithAttribution`](/src/types/fid.ts#:~:text=interface%20FIDMetricWithAttribution) +- [`INPMetricWithAttribution`](/src/types/inp.ts#:~:text=interface%20INPMetricWithAttribution) +- [`LCPMetricWithAttribution`](/src/types/lcp.ts#:~:text=interface%20LCPMetricWithAttribution) +- [`TTFBMetricWithAttribution`](/src/types/ttfb.ts#:~:text=interface%20TTFBMetricWithAttribution) + +#### `MetricRatingThresholds` + +The thresholds of metric's "good", "needs improvement", and "poor" ratings. + +- Metric values up to and including [0] are rated "good" +- Metric values up to and including [1] are rated "needs improvement" +- Metric values above [1] are "poor" + +| Metric value | Rating | +| --------------- | ------------------- | +| ≦ [0] | "good" | +| > [0] and ≦ [1] | "needs improvement" | +| > [1] | "poor" | + +```ts +export type MetricRatingThresholds = [number, number]; +``` + +_See also [Rating Thresholds](#rating-thresholds)._ + +#### `ReportCallback` + +```ts +interface ReportCallback { + (metric: Metric): void; +} +``` + +Metric-specific subclasses: + +- [`CLSReportCallback`](/src/types/cls.ts#:~:text=interface%20CLSReportCallback) +- [`FCPReportCallback`](/src/types/fcp.ts#:~:text=interface%20FCPReportCallback) +- [`FIDReportCallback`](/src/types/fid.ts#:~:text=interface%20FIDReportCallback) +- [`INPReportCallback`](/src/types/inp.ts#:~:text=interface%20INPReportCallback) +- [`LCPReportCallback`](/src/types/lcp.ts#:~:text=interface%20LCPReportCallback) +- [`TTFBReportCallback`](/src/types/ttfb.ts#:~:text=interface%20TTFBReportCallback) + +#### `ReportOpts` + +```ts +interface ReportOpts { + reportAllChanges?: boolean; + durationThreshold?: number; +} +``` + +#### `LoadState` + +The `LoadState` type is used in several of the metric [attribution objects](#attribution). + +```ts +/** + * The loading state of the document. Note: this value is similar to + * `document.readyState` but it subdivides the "interactive" state into the + * time before and after the DOMContentLoaded event fires. + * + * State descriptions: + * - `loading`: the initial document response has not yet been fully downloaded + * and parsed. This is equivalent to the corresponding `readyState` value. + * - `dom-interactive`: the document has been fully loaded and parsed, but + * scripts may not have yet finished loading and executing. + * - `dom-content-loaded`: the document is fully loaded and parsed, and all + * scripts (except `async` scripts) have loaded and finished executing. + * - `complete`: the document and all of its sub-resources have finished + * loading. This is equivalent to the corresponding `readyState` value. + */ +type LoadState = + | 'loading' + | 'dom-interactive' + | 'dom-content-loaded' + | 'complete'; +``` + +#### `FirstInputPolyfillEntry` + +If using the "base+polyfill" build (and if the browser doesn't natively support the Event Timing API), the `metric.entries` reported by `onFID()` will contain an object that polyfills the `PerformanceEventTiming` entry: + +```ts +type FirstInputPolyfillEntry = Omit< + PerformanceEventTiming, + 'processingEnd' | 'toJSON' +>; +``` + +#### `FirstInputPolyfillCallback` + +```ts +interface FirstInputPolyfillCallback { + (entry: FirstInputPolyfillEntry): void; +} +``` + +#### `NavigationTimingPolyfillEntry` + +If using the "base+polyfill" build (and if the browser doesn't support the [Navigation Timing API Level 2](https://www.w3.org/TR/navigation-timing-2/) interface), the `metric.entries` reported by `onTTFB()` will contain an object that polyfills the `PerformanceNavigationTiming` entry using timings from the legacy `performance.timing` interface: + +```ts +type NavigationTimingPolyfillEntry = Omit< + PerformanceNavigationTiming, + | 'initiatorType' + | 'nextHopProtocol' + | 'redirectCount' + | 'transferSize' + | 'encodedBodySize' + | 'decodedBodySize' + | 'type' +> & { + type: PerformanceNavigationTiming['type']; +}; +``` + +#### `WebVitalsGlobal` + +If using the "base+polyfill" build, the `polyfill.js` script creates the global `webVitals` namespace matching the following interface: + +```ts +interface WebVitalsGlobal { + firstInputPolyfill: (onFirstInput: FirstInputPolyfillCallback) => void; + resetFirstInputPolyfill: () => void; + firstHiddenTime: number; +} +``` + +### Functions: + +#### `onCLS()` + +```ts +type onCLS = (callback: CLSReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [CLS](https://web.dev/cls/) value for the current page and calls the `callback` function once the value is ready to be reported, along with all `layout-shift` performance entries that were used in the metric value calculation. The reported value is a [double](https://heycam.github.io/webidl/#idl-double) (corresponding to a [layout shift score](https://web.dev/cls/#layout-shift-score)). + +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. + +_**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)._ + +#### `onFCP()` + +```ts +type onFCP = (callback: FCPReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [FCP](https://web.dev/fcp/) value for the current page and calls the `callback` function once the value is ready, along with the relevant `paint` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). + +#### `onFID()` + +```ts +type onFID = (callback: FIDReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [FID](https://web.dev/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/en-US/docs/Web/API/DOMHighResTimeStamp). + +_**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._ + +#### `onINP()` + +```ts +type onINP = (callback: INPReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [INP](https://web.dev/inp/) value for the current page and calls the `callback` function once the value is ready, along with the `event` performance entries reported for that interaction. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). + +A custom `durationThreshold` [configuration option](#reportopts) can optionally be passed to control what `event-timing` entries are considered for INP reporting. The default threshold is `40`, which means INP scores of less than 40 are reported as 0. Note that this will not affect your 75th percentile INP value unless that value is also less than 40 (well below the recommended [good](https://web.dev/inp/#what-is-a-good-inp-score) threshold). + +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. + +_**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)._ + +#### `onLCP()` + +```ts +type onLCP = (callback: LCPReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [LCP](https://web.dev/lcp/) value for the current page and calls the `callback` function once the value is ready (along with the relevant `largest-contentful-paint` performance entry used to determine the value). The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). + +If the `reportAllChanges` [configuration option](#reportopts) is set to `true`, the `callback` function will be called any time a new `largest-contentful-paint` performance entry is dispatched, or once the final value of the metric has been determined. + +#### `onTTFB()` + +```ts +type onTTFB = (callback: TTFBReportCallback, opts?: ReportOpts) => void; +``` + +Calculates the [TTFB](https://web.dev/time-to-first-byte/) value for the current page and calls the `callback` function once the page has loaded, along with the relevant `navigation` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). + +Note, this function waits until after the page is loaded to call `callback` in order to ensure all properties of the `navigation` entry are populated. This is useful if you want to report on other metrics exposed by the [Navigation Timing API](https://w3c.github.io/navigation-timing/). + +For example, the TTFB metric starts from the page's [time origin](https://www.w3.org/TR/hr-time-2/#sec-time-origin), which means it includes time spent on DNS lookup, connection negotiation, network latency, and server processing time. + +```js +import {onTTFB} from 'web-vitals'; + +onTTFB((metric) => { + // Calculate the request time by subtracting from TTFB + // everything that happened prior to the request starting. + const requestTime = metric.value - metric.entries[0].requestStart; + console.log('Request time:', requestTime); +}); +``` + +_**Note:** 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/en-US/docs/Web/API/DOMHighResTimeStamp)). This ensures code referencing these values (like in the example above) will work the same in all browsers._ + +### Rating Thresholds: + +The thresholds of each metric's "good", "needs improvement", and "poor" ratings are available as [`MetricRatingThresholds`](#metricratingthresholds). + +Example: + +```ts +import {CLSThresholds, FIDThresholds, LCPThresholds} from 'web-vitals'; + +console.log(CLSThresholds); // [ 0.1, 0.25 ] +console.log(FIDThresholds); // [ 100, 300 ] +console.log(LCPThresholds); // [ 2500, 4000 ] +``` + +_**Note:** It's typically not necessary (or recommended) to manually calculate metric value ratings using these thresholds. Use the [`Metric['rating']`](#metric) supplied by the [`ReportCallback`](#reportcallback) functions instead._ + +### Attribution: + +The following objects contain potentially-helpful debugging information that can be sent along with the metric values for the current page visit in order to help identify issues happening to real-users in the field. + +See the [attribution build](#attribution-build) section for details on how to use this feature. + +#### CLS `attribution`: + +```ts +interface CLSAttribution { + /** + * A selector identifying the first element (in document order) that + * shifted when the single largest layout shift contributing to the page's + * CLS score occurred. + */ + largestShiftTarget?: string; + /** + * The time when the single largest layout shift contributing to the page's + * CLS score occurred. + */ + largestShiftTime?: DOMHighResTimeStamp; + /** + * The layout shift score of the single largest layout shift contributing to + * the page's CLS score. + */ + largestShiftValue?: number; + /** + * The `LayoutShiftEntry` representing the single largest layout shift + * contributing to the page's CLS score. (Useful when you need more than just + * `largestShiftTarget`, `largestShiftTime`, and `largestShiftValue`). + */ + largestShiftEntry?: LayoutShift; + /** + * The first element source (in document order) among the `sources` list + * of the `largestShiftEntry` object. (Also useful when you need more than + * just `largestShiftTarget`, `largestShiftTime`, and `largestShiftValue`). + */ + largestShiftSource?: LayoutShiftAttribution; + /** + * The loading state of the document at the time when the largest layout + * shift contribution to the page's CLS score occurred (see `LoadState` + * for details). + */ + loadState?: LoadState; +} +``` + +#### FCP `attribution`: + +```ts +interface FCPAttribution { + /** + * The time from when the user initiates loading the page until when the + * browser receives the first byte of the response (a.k.a. TTFB). + */ + timeToFirstByte: number; + /** + * The delta between TTFB and the first contentful paint (FCP). + */ + firstByteToFCP: number; + /** + * The loading state of the document at the time when FCP `occurred (see + * `LoadState` for details). Ideally, documents can paint before they finish + * loading (e.g. the `loading` or `dom-interactive` phases). + */ + loadState: LoadState; + /** + * The `PerformancePaintTiming` entry corresponding to FCP. + */ + fcpEntry?: PerformancePaintTiming; + /** + * The `navigation` entry of the current page, which is useful for diagnosing + * general page load issues. This can be used to access `serverTiming` for example: + * navigationEntry?.serverTiming + */ + navigationEntry?: PerformanceNavigationTiming | NavigationTimingPolyfillEntry; +} +``` + +#### FID `attribution`: + +```ts +interface FIDAttribution { + /** + * A selector identifying the element that the user interacted with. This + * element will be the `target` of the `event` dispatched. + */ + eventTarget: string; + /** + * The time when the user interacted. This time will match the `timeStamp` + * value of the `event` dispatched. + */ + eventTime: number; + /** + * The `type` of the `event` dispatched from the user interaction. + */ + eventType: string; + /** + * The `PerformanceEventTiming` entry corresponding to FID (or the + * polyfill entry in browsers that don't support Event Timing). + */ + eventEntry: PerformanceEventTiming | FirstInputPolyfillEntry; + /** + * The loading state of the document at the time when the first interaction + * occurred (see `LoadState` for details). If the first interaction occurred + * while the document was loading and executing script (e.g. usually in the + * `dom-interactive` phase) it can result in long input delays. + */ + loadState: LoadState; +} +``` + +#### INP `attribution`: + +```ts +interface INPAttribution { + /** + * A selector identifying the element that the user interacted with for + * the event corresponding to INP. This element will be the `target` of the + * `event` dispatched. + */ + eventTarget?: string; + /** + * The time when the user interacted for the event corresponding to INP. + * This time will match the `timeStamp` value of the `event` dispatched. + */ + eventTime?: number; + /** + * The `type` of the `event` dispatched corresponding to INP. + */ + eventType?: string; + /** + * The `PerformanceEventTiming` entry corresponding to INP. + */ + eventEntry?: PerformanceEventTiming; + /** + * The loading state of the document at the time when the even corresponding + * to INP occurred (see `LoadState` for details). If the interaction occurred + * while the document was loading and executing script (e.g. usually in the + * `dom-interactive` phase) it can result in long delays. + */ + loadState?: LoadState; +} +``` + +#### LCP `attribution`: + +```ts +interface LCPAttribution { + /** + * The element corresponding to the largest contentful paint for the page. + */ + element?: string; + /** + * The URL (if applicable) of the LCP image resource. If the LCP element + * is a text node, this value will not be set. + */ + url?: string; + /** + * The time from when the user initiates loading the page until when the + * browser receives the first byte of the response (a.k.a. TTFB). See + * [Optimize LCP](https://web.dev/optimize-lcp/) for details. + */ + timeToFirstByte: number; + /** + * The delta between TTFB and when the browser starts loading the LCP + * resource (if there is one, otherwise 0). See [Optimize + * LCP](https://web.dev/optimize-lcp/) for details. + */ + resourceLoadDelay: number; + /** + * The total time it takes to load the LCP resource itself (if there is one, + * otherwise 0). See [Optimize LCP](https://web.dev/optimize-lcp/) for + * details. + */ + resourceLoadTime: number; + /** + * The delta between when the LCP resource finishes loading until the LCP + * element is fully rendered. See [Optimize + * LCP](https://web.dev/optimize-lcp/) for details. + */ + elementRenderDelay: number; + /** + * The `navigation` entry of the current page, which is useful for diagnosing + * general page load issues. This can be used to access `serverTiming` for example: + * navigationEntry?.serverTiming + */ + navigationEntry?: PerformanceNavigationTiming | NavigationTimingPolyfillEntry; + /** + * The `resource` entry for the LCP resource (if applicable), which is useful + * for diagnosing resource load issues. + */ + lcpResourceEntry?: PerformanceResourceTiming; + /** + * The `LargestContentfulPaint` entry corresponding to LCP. + */ + lcpEntry?: LargestContentfulPaint; +} +``` + +#### TTFB `attribution`: + +```ts +interface TTFBAttribution { + /** + * The total time from when the user initiates loading the page to when the + * DNS lookup begins. This includes redirects, service worker startup, and + * HTTP cache lookup times. + */ + waitingTime: number; + /** + * The total time to resolve the DNS for the current request. + */ + dnsTime: number; + /** + * The total time to create the connection to the requested domain. + */ + connectionTime: number; + /** + * The time time from when the request was sent until the first byte of the + * response was received. This includes network time as well as server + * processing time. + */ + requestTime: number; + /** + * The `navigation` entry of the current page, which is useful for diagnosing + * general page load issues. This can be used to access `serverTiming` for example: + * navigationEntry?.serverTiming + */ + navigationEntry?: PerformanceNavigationTiming | NavigationTimingPolyfillEntry; +} +``` + +## Browser Support + +The `web-vitals` code has been tested and will run without error in all major browsers as well as Internet Explorer back to version 9. However, some of the APIs required to capture these metrics are currently only available in Chromium-based browsers (e.g. Chrome, Edge, Opera, Samsung Internet). + +Browser support for each function is as follows: + +- `onCLS()`: Chromium +- `onFCP()`: Chromium, Firefox, Safari 14.1+ +- `onFID()`: Chromium, Firefox _(with [polyfill](#how-to-use-the-polyfill): Safari, Internet Explorer)_ +- `onINP()`: Chromium +- `onLCP()`: Chromium +- `onTTFB()`: Chromium, Firefox, Safari 15+ _(with [polyfill](#how-to-use-the-polyfill): Safari 8+, Internet Explorer)_ + +## Limitations + +The `web-vitals` library is primarily a wrapper around the Web APIs that measure the Web Vitals metrics, which means the limitations of those APIs will mostly apply to this library as well. More details on these limitations is available in [this blog post](https://web.dev/crux-and-rum-differences/). + +The primary limitation of these APIs is they have no visibility into `