core-web-vitals-tuner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCore Web Vitals Tuner
Core Web Vitals 调优工具
Improve LCP, INP, and CLS systematically.
系统性优化LCP、INP和CLS指标。
LCP Optimization (<2.5s)
LCP 优化(目标:<2.5秒)
Prioritized Fixes:
-
Optimize images (Biggest impact)html
<!-- Before --> <img src="hero.jpg" /> <!-- After --> <img src="hero.jpg" srcset="hero-400.webp 400w, hero-800.webp 800w, hero-1200.webp 1200w" sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px" loading="eager" fetchpriority="high" /> -
Preload LCP resourcehtml
<link rel="preload" as="image" href="/hero.webp" fetchpriority="high" /> -
Inline critical CSShtml
<style> /* Above-the-fold styles */ .hero { display: flex; height: 100vh; } </style> -
Use CDN
- Serve images from CloudFront/Cloudflare
- Enable HTTP/2 or HTTP/3
优先级修复方案:
-
优化图片(影响最大)html
<!-- Before --> <img src="hero.jpg" /> <!-- After --> <img src="hero.jpg" srcset="hero-400.webp 400w, hero-800.webp 800w, hero-1200.webp 1200w" sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px" loading="eager" fetchpriority="high" /> -
预加载LCP资源html
<link rel="preload" as="image" href="/hero.webp" fetchpriority="high" /> -
内联关键CSShtml
<style> /* Above-the-fold styles */ .hero { display: flex; height: 100vh; } </style> -
使用CDN
- 从CloudFront/Cloudflare等CDN分发图片
- 启用HTTP/2或HTTP/3
INP Optimization (<200ms)
INP 优化(目标:<200毫秒)
Fixes:
-
Debounce expensive interactionstypescript
import { debounce } from "lodash"; const handleSearch = debounce((query) => { fetchResults(query); }, 300); -
Use Web Workers for heavy taskstypescript
const worker = new Worker("processor.js"); worker.postMessage(largeData); worker.onmessage = (e) => console.log(e.data); -
Code splittingtypescript
const HeavyComponent = lazy(() => import("./HeavyComponent"));
修复方案:
-
防抖处理高开销交互typescript
import { debounce } from "lodash"; const handleSearch = debounce((query) => { fetchResults(query); }, 300); -
使用Web Workers处理重负载任务typescript
const worker = new Worker("processor.js"); worker.postMessage(largeData); worker.onmessage = (e) => console.log(e.data); -
代码分割typescript
const HeavyComponent = lazy(() => import("./HeavyComponent"));
CLS Optimization (<0.1)
CLS 优化(目标:<0.1)
Fixes:
-
Reserve space for images/adshtml
<img src="banner.jpg" width="1200" height="600" /> -
Use CSS aspect-ratiocss
.video-container { aspect-ratio: 16 / 9; } -
Avoid injecting content above existingcss
.notification { position: fixed; top: 0; }
修复方案:
-
为图片/广告预留空间html
<img src="banner.jpg" width="1200" height="600" /> -
使用CSS aspect-ratio属性css
.video-container { aspect-ratio: 16 / 9; } -
避免在现有内容上方注入新内容css
.notification { position: fixed; top: 0; }
Verification
验证方法
bash
undefinedbash
undefinedLighthouse CI
Lighthouse CI
npm run lighthouse -- --url=https://example.com
npm run lighthouse -- --url=https://example.com
Web Vitals in production
生产环境中的Web Vitals监控
import { getCLS, getFID, getLCP } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getLCP(console.log);
undefinedimport { getCLS, getFID, getLCP } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getLCP(console.log);
undefinedOutput Checklist
输出检查清单
- LCP optimized (<2.5s)
- INP optimized (<200ms)
- CLS optimized (<0.1)
- Monitoring in place
- Performance regression tests ENDFILE
- LCP已优化(<2.5秒)
- INP已优化(<200毫秒)
- CLS已优化(<0.1)
- 已部署监控方案
- 已配置性能回归测试