# WebPerf Snippets
> A curated collection of JavaScript snippets for web performance measurement in browser consoles and Chrome DevTools.
> Source: https://webperf-snippets.nucliweb.net
---
## Core Web Vitals
- [Cumulative Layout Shift (CLS)](https://webperf-snippets.nucliweb.net/CoreWebVitals/CLS)
Quick check for Cumulative Layout Shift, a Core Web Vital that measures visual stability. CLS tracks how much the page layout shifts unexpectedly during its lifetime, providing a single score that represents the cumulative impact of all unexpected layout shifts. Why this matters: Unexpected layout shifts are frustrating and can cause users to click the wrong element or lose their reading position. CLS directly impacts user experience and is a ranking factor for Google Search. Common causes include images without dimensions, web fonts, and dynamically injected content. CLS Rating Thresholds:
- [Interaction to Next Paint (INP)](https://webperf-snippets.nucliweb.net/CoreWebVitals/INP)
Tracks Interaction to Next Paint, a Core Web Vital that measures responsiveness. INP evaluates how quickly a page responds to user interactions throughout the entire page visit, replacing First Input Delay (FID) as a Core Web Vital in March 2024. Why this matters: INP directly measures user frustration. When users click a button and nothing happens for seconds, they abandon tasks. Unlike FID which only measured first interaction, INP tracks ALL interactions, making it a more comprehensive responsiveness metric and a key ranking factor for Google Search. INP Rating Thresholds:
- [LCP Image Entropy](https://webperf-snippets.nucliweb.net/CoreWebVitals/LCP-Image-Entropy)
Checks if images qualify as LCP candidates based on their entropy (bits per pixel). Since Chrome 112, low-entropy images are ignored for LCP measurement. Based on Stoyan Stefanov's BPP check. What is BPP (Bits Per Pixel)? BPP measures image complexity/entropy: ``` BPP = (file size in bits) / (width × height) = (encodedBodySize × 8) / (width × height) ``` LCP eligibility threshold:
- [LCP Subparts](https://webperf-snippets.nucliweb.net/CoreWebVitals/LCP-Subparts)
Breaks down Largest Contentful Paint into its four phases to identify optimization opportunities. Understanding which phase is slowest helps you focus your optimization efforts where they'll have the most impact. Based on the Web Vitals Chrome Extension. Why this matters: LCP is a critical Core Web Vital that measures when the largest content element becomes visible. By breaking it into sub-parts, you can pinpoint exactly where delays occur and apply targeted optimizations instead of guessing. The four phases of LCP: ```mermaid flowchart LR A([Navigation Start]) --> B["⏱️ TTFB Server Response"] B --> C["⏳ Load Delay Resource Discovery"] C --> D["📥 Load Time Download Resource"] D --> E["🎨 Render Delay Paint Element"] E --> F([✅ LCP Complete]) style B fill:#FFE5E5,stroke:#FF4444,stroke-width:2px style C fill:#FFF3E5,stroke:#FF8800,stroke-width:2px style D fill:#FFFBE5,stroke:#FFBB00,stroke-width:2px style E fill:#E5FFE5,stroke:#44AA44,stroke-width:2px style F fill:#E5F2FF,stroke:#4488FF,stroke-width:3px ```
- [LCP Trail](https://webperf-snippets.nucliweb.net/CoreWebVitals/LCP-Trail)
Tracks every LCP candidate element during page load and highlights each one with a distinct pastel-colored dashed outline — so you can see the full trail from first candidate to final LCP. Each time the browser promotes a larger element as the new LCP, the snippet assigns the next color in the palette and highlights it. All previous candidates remain visible on the page for easy comparison.
- [LCP Video Candidate](https://webperf-snippets.nucliweb.net/CoreWebVitals/LCP-Video-Candidate)
Detects whether the LCP element is a `