mcpField
C
core-web-vitals

core-web-vitals

github.com/kimny1143测试与质量80 次安装
代码仓库

关于 core-web-vitals

用于测量和诊断 Core Web Vitals 及相关页面性能问题的技能,面向 Web 开发者。它涵盖 Lighthouse 检查、按指标排查问题和监控流程。

主要功能

  1. 01LCP、INP、CLS、FCP 和 TTFB 指标指导
  2. 02Lighthouse 测量命令
  3. 03按指标提供诊断步骤
  4. 04Bundle 分析命令
  5. 05性能监控清单

适用场景

  1. 01检查移动端和桌面端性能
  2. 02排查 LCP 或 INP 缓慢问题
  3. 03诊断布局偏移
  4. 04查看生产环境性能指标

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kimny1143/claude-code-template --skill core-web-vitals

安装后在 Claude Code 中输入/core-web-vitals确认已加载。

详细介绍

Core Web Vitals 测量与诊断

专注于性能测量和问题诊断。优化模式请参阅 vercel-react-best-practices。


目标值

指标良好需要改进较差
LCP (Largest Contentful Paint)< 2.5s2.5s - 4.0s> 4.0s
INP (Interaction to Next Paint)< 200ms200ms - 500ms> 500ms
CLS (Cumulative Layout Shift)< 0.10.1 - 0.25> 0.25
FCP (First Contentful Paint)< 1.8s1.8s - 3.0s> 3.0s
TTFB (Time to First Byte)< 800ms800ms - 1800ms> 1800ms

测量命令

Lighthouse CLI
# デスクトップ
npx lighthouse https://example.com --view --preset=desktop

# モバイル
npx lighthouse https://example.com --view --preset=perf --emulated-form-factor=mobile

# アクセシビリティのみ
npx lighthouse http://localhost:3000 --only-categories=accessibility --view

# JSON出力で詳細確認
npx lighthouse http://localhost:3000 --output=json | jq '.audits["largest-contentful-paint"]'
Bundle Analyzer
# Next.js
npm run build
npx @next/bundle-analyzer

# 汎用
npx source-map-explorer 'dist/**/*.js'
Vercel Speed Insights
# Vercelダッシュボードで確認
# Analytics > Speed Insights

按问题诊断

LCP 过慢 (> 2.5s)

确定原因:

npx lighthouse URL --output=json | jq '.audits["largest-contentful-paint-element"]'

主要原因与对策:

原因对策
Hero 图片过大next/image + priority + WebP
Web 字体加载next/font + display: swap
服务器响应过慢缓存、CDN、数据库优化
阻塞渲染的 JS动态导入、defer
INP 过慢 (> 200ms)

确定原因:

  • Chrome DevTools > Performance > Interactions

主要原因与对策:

原因对策
事件处理程序负载过重useTransition、Web Worker
重新渲染过多使用 React DevTools Profiler 检查
JS 任务耗时过长拆分任务、requestIdleCallback
CLS 过高 (> 0.1)

确定原因:

npx lighthouse URL --output=json | jq '.audits["layout-shift-elements"]'

主要原因与对策:

原因对策
未指定图片尺寸必须指定 width / height
插入动态内容使用骨架屏预留空间
Web 字体切换font-display: swap + fallback
广告/嵌入内容使用固定尺寸容器
FCP 过慢 (> 1.8s)

主要原因与对策:

原因对策
初始 HTML 过大Server Components、流式传输
阻塞渲染的 CSS内联关键 CSS
TTFB 过慢优化服务器

检查清单

测量
  • 分别检查 Lighthouse 移动端和桌面端
  • 使用实际设备检查(与模拟结果存在差异)
  • 在生产环境中测量(开发环境的数据仅供参考)
监控
  • 配置 Vercel Speed Insights
  • 设置警报阈值(例如 LCP > 3s)
  • 定期查看报告

相关技能

  • vercel-react-best-practices:优化模式(57 条规则)
  • ui-ux-pro-max:无障碍性(WCAG 对比度)

评论

支持 Markdown