Skip to content

Commit 7e6f29a

Browse files
style: format debug optimize lcp skill
1 parent e6caa88 commit 7e6f29a

4 files changed

Lines changed: 40 additions & 22 deletions

File tree

skills/debug-optimize-lcp/SKILL.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ LCP is a Core Web Vital that directly affects user experience and search ranking
1717

1818
Every page's LCP breaks down into four sequential subparts with no gaps or overlaps. Understanding which subpart is the bottleneck is the key to effective optimization.
1919

20-
| Subpart | Ideal % of LCP | What it measures |
21-
|---------|---------------|------------------|
22-
| **Time to First Byte (TTFB)** | ~40% | Navigation start → first byte of HTML received |
23-
| **Resource load delay** | <10% | TTFB → browser starts loading the LCP resource |
24-
| **Resource load duration** | ~40% | Time to download the LCP resource |
25-
| **Element render delay** | <10% | LCP resource downloaded → LCP element rendered |
20+
| Subpart | Ideal % of LCP | What it measures |
21+
| ----------------------------- | -------------- | ---------------------------------------------- |
22+
| **Time to First Byte (TTFB)** | ~40% | Navigation start → first byte of HTML received |
23+
| **Resource load delay** | <10% | TTFB → browser starts loading the LCP resource |
24+
| **Resource load duration** | ~40% | Time to download the LCP resource |
25+
| **Element render delay** | <10% | LCP resource downloaded → LCP element rendered |
2626

2727
The "delay" subparts should be as close to zero as possible. If either delay subpart is large relative to the total LCP, that's the first place to optimize.
2828

@@ -66,6 +66,7 @@ Use `list_network_requests` to see when the LCP resource loaded relative to othe
6666
- Then use `get_network_request` with the LCP resource's request ID for full details.
6767

6868
**Key Checks:**
69+
6970
- **Start Time**: Compare against the HTML document and the first resource. If the LCP resource starts much later than the first resource, there's resource load delay to eliminate.
7071
- **Duration**: A large resource load duration suggests the file is too big or the server is slow.
7172

@@ -78,28 +79,36 @@ Use `evaluate_script` with the **"Audit Common Issues" snippet** found in [refer
7879
After identifying the bottleneck subpart, apply these prioritized fixes.
7980

8081
### 1. Eliminate Resource Load Delay (target: <10%)
82+
8183
The most common bottleneck. The LCP resource should start loading immediately.
84+
8285
- **Root Cause**: LCP image loaded via JS/CSS, `data-src` usage, or `loading="lazy"`.
8386
- **Fix**: Use standard `<img>` with `src`. **Never** lazy-load the LCP image.
8487
- **Fix**: Add `<link rel="preload" fetchpriority="high">` if the image isn't discoverable in HTML.
8588
- **Fix**: Add `fetchpriority="high"` to the LCP `<img>` tag.
8689

8790
### 2. Eliminate Element Render Delay (target: <10%)
91+
8892
The element should render immediately after loading.
93+
8994
- **Root Cause**: Large stylesheets, synchronous scripts in `<head>`, or main thread blocking.
9095
- **Fix**: Inline critical CSS, defer non-critical CSS/JS.
9196
- **Fix**: Break up long tasks blocking the main thread.
9297
- **Fix**: Use Server-Side Rendering (SSR) so the element exists in initial HTML.
9398

9499
### 3. Reduce Resource Load Duration (target: ~40%)
100+
95101
Make the resource smaller or faster to deliver.
102+
96103
- **Fix**: Use modern formats (WebP, AVIF) and responsive images (`srcset`).
97104
- **Fix**: Serve from a CDN.
98105
- **Fix**: Set `Cache-Control` headers.
99106
- **Fix**: Use `font-display: swap` if LCP is text blocked by a web font.
100107

101108
### 4. Reduce TTFB (target: ~40%)
109+
102110
The HTML document itself takes too long to arrive.
111+
103112
- **Fix**: Minimize redirects and optimize server response time.
104113
- **Fix**: Cache HTML at the edge (CDN).
105114
- **Fix**: Ensure pages are eligible for back/forward cache (bfcache).

skills/debug-optimize-lcp/references/lcp-breakdown.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LCP measures the time from when the user initiates loading the page until the la
66

77
Every page's LCP consists of these four subcategories. There's no gap or overlap between them, and they add up to the full LCP time.
88

9-
| LCP subpart | % of LCP (Optimal) | Description |
10-
|---|---|---|
11-
| **Time to First Byte (TTFB)** | ~40% | The time from when the user initiates loading the page until the browser receives the first byte of the HTML document response. |
12-
| **Resource load delay** | <10% | The time between TTFB and when the browser starts loading the LCP resource. If the LCP element doesn't require a resource load (e.g., system font text), this time is 0. |
13-
| **Resource load duration** | ~40% | The duration of time it takes to load the LCP resource itself. If the LCP element doesn't require a resource load, this time is 0. |
14-
| **Element render delay** | <10% | The time between when the LCP resource finishes loading and the LCP element rendering fully. |
9+
| LCP subpart | % of LCP (Optimal) | Description |
10+
| ----------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
11+
| **Time to First Byte (TTFB)** | ~40% | The time from when the user initiates loading the page until the browser receives the first byte of the HTML document response. |
12+
| **Resource load delay** | <10% | The time between TTFB and when the browser starts loading the LCP resource. If the LCP element doesn't require a resource load (e.g., system font text), this time is 0. |
13+
| **Resource load duration** | ~40% | The duration of time it takes to load the LCP resource itself. If the LCP element doesn't require a resource load, this time is 0. |
14+
| **Element render delay** | <10% | The time between when the LCP resource finishes loading and the LCP element rendering fully. |
1515

1616
## Why the Breakdown Matters
1717

skills/debug-optimize-lcp/references/lcp-snippets.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Use these JavaScript snippets with the `evaluate_script` tool to extract deep insights from the page.
44

55
## 1. Identify LCP Element
6+
67
Use this snippet to identify the LCP element and get raw timing data from the Performance API.
78

89
```javascript
910
async () => {
10-
return await new Promise((resolve) => {
11-
new PerformanceObserver((list) => {
11+
return await new Promise(resolve => {
12+
new PerformanceObserver(list => {
1213
const entries = list.getEntries();
1314
const last = entries[entries.length - 1];
1415
resolve({
@@ -21,12 +22,13 @@ async () => {
2122
loadTime: last.loadTime,
2223
size: last.size,
2324
});
24-
}).observe({ type: 'largest-contentful-paint', buffered: true });
25+
}).observe({type: 'largest-contentful-paint', buffered: true});
2526
});
26-
}
27+
};
2728
```
2829

2930
## 2. Audit Common Issues
31+
3032
Use this snippet to check for common DOM-based LCP issues (lazy loading, priority).
3133

3234
```javascript
@@ -40,7 +42,7 @@ Use this snippet to check for common DOM-based LCP issues (lazy loading, priorit
4042
issues.push({
4143
issue: 'lazy-loaded image in viewport',
4244
element: img.outerHTML.substring(0, 200),
43-
fix: 'Remove loading="lazy" from this image — it is in the initial viewport and may be the LCP element'
45+
fix: 'Remove loading="lazy" from this image — it is in the initial viewport and may be the LCP element',
4446
});
4547
}
4648
});
@@ -52,23 +54,26 @@ Use this snippet to check for common DOM-based LCP issues (lazy loading, priorit
5254
issues.push({
5355
issue: 'large viewport image without fetchpriority',
5456
element: img.outerHTML.substring(0, 200),
55-
fix: 'Add fetchpriority="high" to this image — it is large and visible in the initial viewport'
57+
fix: 'Add fetchpriority="high" to this image — it is large and visible in the initial viewport',
5658
});
5759
}
5860
});
5961

6062
// Check for render-blocking scripts in head
61-
document.querySelectorAll('head script:not([async]):not([defer]):not([type="module"])')
63+
document
64+
.querySelectorAll(
65+
'head script:not([async]):not([defer]):not([type="module"])',
66+
)
6267
.forEach(script => {
6368
if (script.src) {
6469
issues.push({
6570
issue: 'render-blocking script in head',
6671
element: script.outerHTML.substring(0, 200),
67-
fix: 'Add async or defer attribute, or move to end of body'
72+
fix: 'Add async or defer attribute, or move to end of body',
6873
});
6974
}
7075
});
7176

72-
return { issueCount: issues.length, issues };
73-
}
77+
return {issueCount: issues.length, issues};
78+
};
7479
```

skills/debug-optimize-lcp/references/optimization-strategies.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# LCP Optimization Strategies
22

33
## 1. Eliminate Resource Load Delay
4+
45
**Goal**: Ensure the LCP resource starts loading as early as possible.
56

67
- **Early Discovery**: Ensure the LCP resource is discoverable in the initial HTML document response (not dynamically added by JS or hidden in `data-src`).
@@ -10,6 +11,7 @@
1011
- **Same Origin**: Host critical resources on the same origin or use `<link rel="preconnect">`.
1112

1213
## 2. Eliminate Element Render Delay
14+
1315
**Goal**: Ensure the LCP element can render immediately after its resource has finished loading.
1416

1517
- **Minimize Render-Blocking CSS**: Inline critical CSS and defer non-critical CSS. Ensure the stylesheet is smaller than the LCP resource.
@@ -18,6 +20,7 @@
1820
- **Break Up Long Tasks**: Prevent large JavaScript tasks from blocking the main thread during rendering.
1921

2022
## 3. Reduce Resource Load Duration
23+
2124
**Goal**: Reduce the time spent transferring the bytes of the resource.
2225

2326
- **Optimize Resource Size**: Serve optimal image sizes, use modern formats (AVIF, WebP), and compress images/fonts.
@@ -26,6 +29,7 @@
2629
- **Caching**: Use efficient `Cache-Control` policies.
2730

2831
## 4. Reduce Time to First Byte (TTFB)
32+
2933
**Goal**: Deliver the initial HTML as quickly as possible.
3034

3135
- **Minimize Redirects**: Avoid multiple redirects from advertisements or shortened links.

0 commit comments

Comments
 (0)