132-5988-3308

文章资讯

记录团队成长点滴以及对技术、理念的探索,同时我们乐于分享!

2026?Web??????:?Core Web Vitals?????????

2026-07-08 栏目:技术学堂 354

??:Web??????2026???????

2026?,Web????"????"???"????"???Google?????,?????????1?,?????20%;???????????????3?,?2026???????????????1?????????,Google??Core Web Vitals??????????--????????????,???????????????

??????????Web???????,?Core Web Vitals???????????????,????????????????,????2026?????????

Web???????

?:????????????

??Core Web Vitals????:?????????

1.1 ???Core Web Vitals????

Core Web Vitals?Google?2020????????????,??????,2026?????????????????PageSpeed Insights??,Core Web Vitals??????????,????????????:??Core Web Vitals,?????????????????

??????????:

?? ?? ???? ????
LCP Largest Contentful Paint ???????? ?2.5?
INP Interaction to Next Paint ?????? ?200ms
CLS Cumulative Layout Shift ????? ?0.1

1.2 LCP??:?2.8??1.5??????

LCP?Core Web Vitals???????,???????????(????????????)??????2026?,Google?LCP?"??"??????2.5??

??LCP?(>2.5?)?????:

  • ?????????(TTFB>600ms)
  • ????????(CSS/JS??)
  • ?????(???????????)
  • ???????(CSR)????????

LCP???????:

???:?????????(TTFB)

TTFB(Time To First Byte)?LCP?????????:?600ms???????:??CDN???????????????(?Redis)?????????????????TTFB?1200ms???450ms,LCP??????37%?

???:??LCP????

?????LCP??(??????????????),?????:

  • ?????:??WebP/AVIF???????width/height?????fetchpriority="high"????????
  • ?????:??????????CSS??????

???:??????

// ??:?????LCP??
<link rel="preload" as="image" 
      href="/images/hero.webp" 
      fetchpriority="high">

// ??:CSS????
<link rel="stylesheet" href="non-critical.css" 
      media="print" onload="this.media='all'">

1.3 INP??:2026?????

INP?2024???FID(First Input Delay)????,??????????(????????)???????????INP??????????,?????????????????,????????

INP???:

INP = ???? + ???? + ????

??INP??????????:

??????:

  • ???????,???????
  • ??requestIdleCallback???????
  • ????????????JavaScript
// ??:??requestIdleCallback???????
function processAnalytics() {
  requestIdleCallback(() => {
    // ????????????
    sendAnalyticsData();
  }, { timeout: 2000 });
}

// ??:????,????
function processLargeArray(items) {
  const CHUNK_SIZE = 100;
  let index = 0;
  
  function processChunk() {
    const chunk = items.slice(index, index + CHUNK_SIZE);
    chunk.forEach(processItem);
    index += CHUNK_SIZE;
    
    if (index < items.length) {
      // ?????,?????
      setTimeout(processChunk, 0);
    }
  }
  
  processChunk();
}

?????(Long Tasks):

?????????50ms?????"???",?INP????????Chrome DevTools?Performance?????????,?????5ms???????

1.4 CLS??:????????

CLS??????????????????????2026?????CLS????--???????????????,???????????????,??????????

??CLS?????:

  • ??/???????
  • ??????(????????)
  • ??????????(FOIT/FOUT)
  • ?????Web Components

??CLS?????:

// 1. ?????/??????
<img src="hero.jpg" width="800" height="400" alt="...">

// 2. ??aspect-ratio??
.hero-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #f0f0f0; /* ??? */
}

// 3. ??????
@font-face {
  font-family: 'MyFont';
  src: url('/fonts/MyFont.woff2') format('woff2');
  font-display: swap; /* ??FOIT */
}

// 4. ?????
.ad-slot {
  min-height: 250px; /* ?????? */
}

????????:2026?????

2.1 ????:??????????

?????????????,???????LCP???????2026????????:

????????:

  • WebP:?JPEG?25-35%,?????,????
  • AVIF:?WebP??50%,?Safari????(15.4+)
  • JPEG XL:??????,????????

???????:

<picture>
  <source 
    type="image/avif"
    srcset="hero-400.avif 400w,
            hero-800.avif 800w,
            hero-1200.avif 1200w"
    sizes="(max-width: 600px) 100vw, 50vw">
  <source 
    type="image/webp"
    srcset="hero-400.webp 400w,
            hero-800.webp 800w,
            hero-1200.webp 1200w"
    sizes="(max-width: 600px) 100vw, 50vw">
  <img 
    src="hero-800.jpg" 
    alt="Hero image"
    width="800" 
    height="400"
    loading="lazy"
    decoding="async">
</picture>

????(LCP??)????loading="lazy":

<!-- ??LCP??:??eager??,??? -->
<link rel="preload" as="image" href="/images/hero.webp" fetchpriority="high">
<img src="/images/hero.webp" fetchpriority="high" loading="eager">

<!-- ?????:??lazy?? -->
<img src="/images/below-fold.webp" loading="lazy" decoding="async">

2.2 JavaScript??:???????

JavaScript???Web??????????????:

????????:

// ???????????
const handleLogin = async () => {
  const { showLoginModal } = await import('./login-modal.js');
  showLoginModal();
};

// React???????
const HeavyComponent = React.lazy(() => import('./HeavyComponent'));

// Vue??????
const AsyncComponent = defineAsyncComponent(() => 
  import('./AsyncComponent.vue')
);

Tree Shaking?????:

????????(Vite?Webpack 5?Rspack)?Tree Shaking??,?????????????Terser?esbuild??????????

???????:

  • ??????????????
  • ??