Web Vitals
- First Contentful Paint (FCP) - RESPONSE QUICK
- Largest Contentful Paint (LCP) - GET TO THE POINT
- Cumulative Layout Shift (CLS) - DON'T MOVE STUFF
- First Contentful Paint (FID) - DON'T LOAD TOO MUCH
Google Chrome web vitals: https://github.com/GoogleChrome/web-vitals
Lighthouse
Lab data vs Field data https://www.lightest.app/
Performance Analytics
- CLS is inversely correlated to Session Time
- LCP is inversely correlated to Bounce Rate
Optimizing Metrics
Improving FCP
- Sized Correctly (Hardware, VM, network, etc)
- Minimal Processing
- Network Bandwidth (compression, cdn...)
Improving LCP
Defer resources until later
- async vs defer
defer will defer js execution after LCP
- Lazy loading
We could use IntersectionObserver to detect when an element becomes visible in window and load it.
1 | var lazyObserver = new IntersectionObserver(function(entries) { |
Responsive Images
Let image downloads based on the viewport size.
HTTP2, Caching, and Pre-loading
- HTTP2 allows us to reuse the connections, yet not all servers support them
- Caching
1
2
3cache-control: max-age=600
expires: Wed, 20 Jan 2021 03:13:21 GMT
etag: "600a4af-c96f" - Preloading Use annotations of preconnect and preload to preload CSS fonts => reduce the time between FCP and LCP
Improving CLS practice
Be careful with relative position and prefer reserve space for large image