debug-optimize-lcp
π―SkillHelps you find out why the main content of a web page appears slowly, and how to fix it. It uses Chrome DevTools tools to record a page load, measure each stage and point to the slowest part.
Installation
npx skills add chromedevtools/chrome-devtools-mcp --skill debug-optimize-lcpRun it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).
Uses skills.sh Β· Node.js 22.20+
After installing
Ask for related work and the agent uses it on its own, or call it yourself.
/debug-optimize-lcpInstall by hand
Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.
Open the skill folder β- This project
.claude/skills/debug-optimize-lcp/ - All projects
~/.claude/skills/debug-optimize-lcp/
These paths are for Claude Code. For other tools, the command above puts it in the right place.
SKILL.md
View on GitHub βGuides debugging and optimizing Largest Contentful Paint (LCP) using Chrome DevTools MCP tools. Use this skill whenever the user asks about LCP performance, slow page loads, Core Web Vitals optimization, or wants to understand why their page's main content takes too long to appear. Also use when the user mentions "largest contentful paint", "page load speed", "CWV", or wants to improve how fast their hero image or main content renders.
What is LCP and why it matters
Largest Contentful Paint (LCP) measures how quickly a page's main content becomes visible. It's the time from navigation start until the largest image or text block renders in the viewport.
- Good: 2.5 seconds or less
- Needs improvement: 2.5β4.0 seconds
- Poor: greater than 4.0 seconds
LCP is a Core Web Vital that directly affects user experience and search ranking. On 73% of mobile pages, the LCP element is an image.
LCP Subparts Breakdown
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.
| Subpart | Ideal % of LCP | What it measures |
|---|---|---|
| Time to First Byte (TTFB) | ~40% | Navigation start β first byte of HTML received |
| Resource load delay | <10% | TTFB β browser starts loading the LCP resource |
| Resource load duration | ~40% | Time to download the LCP resource |
| Element render delay | <10% | LCP resource downloaded β LCP element rendered |
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.
Common Pitfall: Optimizing one subpart (like compressing an image to reduce load duration) without checking others. If render delay is the real bottleneck, a smaller image won't help β the saved time just shifts to render delay.
Debugging Workflow
Follow these steps in order. Each step builds on the previous one.
Step 1: Record a Performance Trace
Navigate to the page, then record a trace with reload to capture the full page load including LCP:
navigate_pagewithpageIdto the target URL.performance_start_tracewithpageId,reload: trueandautoStop: true.
The trace results will include LCP timing and available insight sets. Note the insight set IDs from the output β you'll need them in the next step.
Step 2: Analyze LCP Insights
Use performance_analyze_insight to drill into LCP-specific insights. Look for these insight names in the trace results:
- LCPBreakdown β Shows the four LCP subparts with timing for each.
- DocumentLatency β Server response time issues affecting TTFB.
- RenderBlocking β Resources blocking the LCP element from rendering.
- LCPDiscovery β Whether the LCP resource was discoverable early.
Call performance_analyze_insight with pageId, the insight set ID, and the insight name from the trace results.
Step 3: Identify the LCP Element
Use evaluate_script (with pageId) and the "Identify LCP Element" snippet found in references/lcp-snippets.md to reveal the LCP element's tag, resource URL, and raw timing data.
The url field tells you what resource to look for in the network waterfall. If url is empty, the LCP element is text-based (no resource to load).
Step 4: Check the Network Waterfall
Use list_network_requests to see when the LCP resource loaded relative to other resources:
- Call
list_network_requestswithpageIdfiltered byresourceTypes: ["image", "font"](adjust based on Step 3). - Then use
get_network_requestwithpageIdand the LCP resource's request ID for full details.
Key Checks:
- 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.
- Duration: A large resource load duration suggests the file is too big or the server is slow.
Step 5: Inspect HTML for Common Issues
Use evaluate_script (with pageId) and the "Audit Common Issues" snippet found in references/lcp-snippets.md to check for lazy-loaded images in the viewport, missing fetchpriority, and render-blocking scripts.
Optimization Strategies
After identifying the bottleneck subpart, apply these prioritized fixes.
1. Eliminate Resource Load Delay (target: <10%)
The most common bottleneck. The LCP resource should start loading immediately.
- Root Cause: LCP image loaded via JS/CSS,
data-srcusage, orloading="lazy". - Fix: Use standard
<img>withsrc. Never lazy-load the LCP image. - Fix: Add
<link rel="preload" fetchpriority="high">if the image isn't discoverable in HTML. - Fix: Add
fetchpriority="high"to the LCP<img>tag.
2. Eliminate Element Render Delay (target: <10%)
The element should render immediately after loading.
- Root Cause: Large stylesheets, synchronous scripts in
<head>, or main thread blocking. - Fix: Inline critical CSS, defer non-critical CSS/JS.
- Fix: Break up long tasks blocking the main thread.
- Fix: Use Server-Side Rendering (SSR) so the element exists in initial HTML.
3. Reduce Resource Load Duration (target: ~40%)
Make the resource smaller or faster to deliver.
- Fix: Use modern formats (WebP, AVIF) and responsive images (
srcset). - Fix: Serve from a CDN.
- Fix: Set
Cache-Controlheaders. - Fix: Use
font-display: swapif LCP is text blocked by a web font.
4. Reduce TTFB (target: ~40%)
The HTML document itself takes too long to arrive.
- Fix: Minimize redirects and optimize server response time.
- Fix: Cache HTML at the edge (CDN).
- Fix: Ensure pages are eligible for back/forward cache (bfcache).
Verifying Fixes & Emulation
- Verification: Re-run the trace (
performance_start_tracewithpageIdandreload: true) and compare the new subpart breakdown. The bottleneck should shrink. - Emulation: Lab measurements differ from real-world experience. Use
emulateto test under constraints:emulatewithpageId,networkConditions: "Fast 3G"andcpuThrottlingRate: 4.- This surfaces issues visible only on slower connections/devices.
More from this repository8
Lets your AI coding tool open and control a real Chrome browser. It can test pages, find bugs, take screenshots, and check how fast a site loads.
Chrome DevTools for coding agents
Chrome DevTools MCP is an official MCP server from the Chrome DevTools team that lets AI coding agents control and inspect a live Chrome browser.
Lets your AI agent control and inspect a Chrome browser to debug web pages. It can open pages, click and fill in forms, take screenshots, check page speed, read styles, and watch network traffic, through the chrome-devtools-mcp tool.
Lets you control the Chrome browser from your terminal with simple commands. You can open pages, click, type into forms and take page snapshots, or put these steps in shell scripts to automate browser tasks.
Helps find and fix accessibility problems on web pages, so people using screen readers or keyboards can use them. It drives a Chrome browser to run audits and check labels, focus, color contrast and tap target size.
Helps fix setup problems when your AI assistant cannot connect to Chrome through Chrome DevTools MCP, a tool that lets AI control the browser. It reads your config file, matches common error messages and walks you through fixes step by step.
Helps find and fix memory leaks in JavaScript and Node.js apps, where an app keeps using more and more memory. It uses Chrome DevTools tools to take and compare memory snapshots and find what is holding on to memory.