debug-optimize-lcp by chromedevtools/chrome-devtools-mcp
npx skills add https://github.com/chromedevtools/chrome-devtools-mcp --skill debug-optimize-lcp最大内容绘制 (LCP) 衡量页面主要内容变为可见的速度。它指的是从导航开始到视口中渲染出最大图像或文本块所花费的时间。
LCP 是一项核心 Web 指标,直接影响用户体验和搜索排名。在 73% 的移动页面上,LCP 元素是一张图片。
每个页面的 LCP 都可以细分为四个连续且无间隙或重叠的部分。了解哪个部分是瓶颈是有效优化的关键。
| 组成部分 | 占 LCP 的理想比例 | 衡量内容 |
|---|---|---|
| 首字节时间 (TTFB) | ~40% | 导航开始 → 接收到 HTML 的第一个字节 |
| 资源加载延迟 | <10% | TTFB → 浏览器开始加载 LCP 资源 |
| 资源加载时长 | ~40% | 下载 LCP 资源所需的时间 |
| 元素渲染延迟 | <10% | LCP 资源下载完成 → LCP 元素渲染完成 |
"延迟"部分应尽可能接近零。如果任一延迟部分相对于总 LCP 时间较长,那就是首先需要优化的地方。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
常见误区 : 优化一个部分(例如压缩图像以减少加载时长)而不检查其他部分。如果渲染延迟是真正的瓶颈,更小的图像将无济于事——节省的时间只会转移到渲染延迟上。
请按顺序遵循以下步骤。每一步都建立在前一步的基础上。
导航到页面,然后记录一个包含重新加载的追踪,以捕获包括 LCP 在内的完整页面加载过程:
navigate_page 到目标 URL。performance_start_trace 并设置 reload: true 和 autoStop: true。追踪结果将包含 LCP 计时和可用的洞察集合。请记下输出中的洞察集合 ID —— 您将在下一步中需要它们。
使用 performance_analyze_insight 深入分析 LCP 相关的具体洞察。在追踪结果中查找以下洞察名称:
调用 performance_analyze_insight 时,需要传入洞察名称和从追踪结果中获得的洞察集合 ID。
使用 evaluate_script 并配合在 references/lcp-snippets.md 中找到的 "识别 LCP 元素" 代码片段,以揭示 LCP 元素的标签、资源 URL 和原始计时数据。
url 字段告诉您在网络瀑布图中需要查找哪个资源。如果 url 为空,则 LCP 元素是基于文本的(没有需要加载的资源)。
使用 list_network_requests 查看 LCP 资源相对于其他资源的加载时间:
list_network_requests,按 resourceTypes: ["Image", "Font"] 进行过滤(根据步骤 3 的结果进行调整)。get_network_request 并传入 LCP 资源的请求 ID 以获取完整详情。关键检查项:
使用 evaluate_script 并配合在 references/lcp-snippets.md 中找到的 "审计常见问题" 代码片段,检查视口中是否存在延迟加载的图像、缺少 fetchpriority 属性以及渲染阻塞的脚本。
在识别出瓶颈部分后,应用以下按优先级排序的修复措施。
最常见的瓶颈。LCP 资源应立即开始加载。
data-src 或 loading="lazy"。src 的标准 <img> 标签。切勿对 LCP 图像进行延迟加载。<link rel="preload" fetchpriority="high">。<img> 标签中添加 fetchpriority="high"。元素应在加载完成后立即渲染。
<head> 中的同步脚本或主线程阻塞。使资源更小或交付更快。
srcset)。Cache-Control 响应头。font-display: swap。HTML 文档本身到达时间过长。
reload: true 的 performance_start_trace)并比较新的组成部分细分。瓶颈部分应该缩小。emulate 在限制条件下进行测试:
emulate 并设置 networkConditions: "Fast 3G" 和 cpuThrottlingRate: 4。每周安装次数
70
代码仓库
GitHub 星标数
28.2K
首次出现
14 天前
安全审计
安装于
codex69
gemini-cli67
amp67
github-copilot67
opencode67
cursor67
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.
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.
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.
Follow these steps in order. Each step builds on the previous one.
Navigate to the page, then record a trace with reload to capture the full page load including LCP:
navigate_page to the target URL.performance_start_trace with reload: true and autoStop: 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.
Use performance_analyze_insight to drill into LCP-specific insights. Look for these insight names in the trace results:
Call performance_analyze_insight with the insight name and the insight set ID from the trace results.
Use evaluate_script with 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).
Use list_network_requests to see when the LCP resource loaded relative to other resources:
list_network_requests filtered by resourceTypes: ["Image", "Font"] (adjust based on Step 3).get_network_request with the LCP resource's request ID for full details.Key Checks:
Use evaluate_script with 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.
After identifying the bottleneck subpart, apply these prioritized fixes.
The most common bottleneck. The LCP resource should start loading immediately.
data-src usage, or loading="lazy".<img> with src. Never lazy-load the LCP image.<link rel="preload" fetchpriority="high"> if the image isn't discoverable in HTML.fetchpriority="high" to the LCP <img> tag.The element should render immediately after loading.
<head>, or main thread blocking.Make the resource smaller or faster to deliver.
srcset).Cache-Control headers.font-display: swap if LCP is text blocked by a web font.The HTML document itself takes too long to arrive.
performance_start_trace with reload: true) and compare the new subpart breakdown. The bottleneck should shrink.emulate to test under constraints:
emulate with networkConditions: "Fast 3G" and cpuThrottlingRate: 4.Weekly Installs
70
Repository
GitHub Stars
28.2K
First Seen
14 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex69
gemini-cli67
amp67
github-copilot67
opencode67
cursor67
GSAP 框架集成指南:Vue、Svelte 等框架中 GSAP 动画最佳实践
3,200 周安装