Comments (3)
You do not need to wait for DCL to use any of these APIs.
As @Zizzamia mentions, PerformanceObserver
now has buffering, which means you can observe entries both before or after they happen and still have the callback invoked.
But then further down you do:
The only reason that example waits for DOMContentLoaded
is because it's loading the UMD version of the script via a separate script tag (note how there are two script tags in that example). The DOMContentLoaded
check is not to wait to call the functions, it's waiting to ensure the first script is loaded and the webVitals
global variable is ready.
Note, you do not need to wait if you're loading via <script type=module>
or using a module bundler (either of which are recommended over using the UMD version).
from web-vitals.
Also I know TTFB and in particular
performance.getEntriesByType('navigation')
is not available right away, that's why we do theafterLoad
callback internally.Mention these, I personally have some confusion on this topic as well. @philipwalton what's your thoughts on this, and does the Chrome team have more research on this topic?
In general, the recommended approach for the future is to not use performance.getEntries...
and to use PerformanceObserver
instead—for exactly the issue you raised.
The only reason I used performance.getEntriesByType('navigation')
in this library is to get wider browser support, but as you noted that requires waiting until after the load event.
from web-vitals.
Generally, all Performance Observer values are buffered (check https://github.com/GoogleChrome/web-vitals/blob/master/src/lib/observe.ts#L38), to be even accessible at a later stage of the application.
The specs says
There are special considerations regarding initial page load when using the PerformanceObserver interface: a registration must be active to receive events but the registration script may not be available or may not be desired in the critical path. To address this, user agents buffer some number of events while the page is being constructed, and these buffered events can be accessed via the buffered flag when registering the observer. When this flag is set, the user agent retrieves and dispatches events that it has buffered, for the specified entry type, and delivers them in the first callback after the observe() call occurs.
Also I know TTFB and in particular performance.getEntriesByType('navigation')
is not available right away, that's why we do the afterLoad
callback internally.
Mention these, I personally have some confusion on this topic as well. @philipwalton what's your thoughts on this, and does the Chrome team have more research on this topic?
from web-vitals.
Related Issues (20)
- differences in TTFB in safari vs chromium based browsers HOT 1
- LCP value setting to 0 intermittently HOT 7
- Add INP breakdown entries to the attribution build HOT 3
- User consent policy HOT 1
- Firefox LCP tests failing
- Bug: LCP attribution can include `resourceLoadDelay` attribution timings far greater than the LCP value in cases where `onTTFB` discards the navigation data HOT 1
- FCP and TTFB are triggered multiple times HOT 7
- contributing LoAF basesd code that idenifies LoAF, INF and JS long tasks data HOT 1
- Capturing metadata with events HOT 2
- Allow to reset the INP calculation HOT 2
- v4 giving undefined TypeError HOT 1
- INP: Probably a bad measurement metric for web vitals - even with simple HTML structure pages with no CSS will cause bad value. HOT 1
- Expose INP target element as first class citizen in attribution HOT 2
- Expose ability to reset internal state of metrics (specifically INP) HOT 2
- v4 INP attribution ending processingEnd time in the wrong animation frame HOT 8
- CDN JS - Web server is returning an unknown error HOT 4
- CLS and INP are being calculated incorrectly HOT 2
- Suggestion to track all attributions HOT 4
- CLS being reported due to filter CSS transition HOT 3
- Firefox e2e tests flakey HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-vitals.