LCP, FID, CLS 심층 분석
Largest Contentful Paint(LCP), First Input Delay(FID), Cumulative Layout Shift(CLS)를 자세히 분석하고 최적화 기법을 학습합니다.
LCP, FID, CLS 심층 분석은(는) CoddyKit의 무료 Web Performance Optimization & Lighthouse 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Web Performance Optimization & Lighthouse 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Web Performance Optimization & Lighthouse 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Core Web Vitals Deep Dive
Welcome to a deeper look into the Core Web Vitals! These metrics are crucial for understanding and improving your website's user experience.
In this lesson, we'll analyze Largest Contentful Paint (LCP), First Input Delay (FID), and Cumulative Layout Shift (CLS). You'll learn what each measures, why they matter, and practical techniques to optimize them.
Largest Contentful Paint (LCP)
Largest Contentful Paint (LCP) measures the time it takes for the largest content element visible within the viewport to render. Think of it as how quickly a user sees the main content of your page.
- A good LCP score is 2.5 seconds or less.
- Anything above 4 seconds is considered poor.
LCP is a key indicator of your page's perceived loading speed.
What Counts for LCP?
Not all elements contribute to LCP. Typically, the largest image or text block that's visible when the page first loads is the LCP element. Common LCP elements include:
<img>elements<video>elements (using their poster image)- Elements with a background image loaded via
url() - Block-level text elements containing text nodes (e.g.,
<h1>,<p>)
Knowing your LCP element is the first step to optimizing it!
Optimizing LCP: Speeding Up Resources
A major factor for LCP is how quickly your browser can fetch and render critical resources, especially images and fonts. Here's a common strategy:
- Preload critical images: Use
<link rel="preload">to tell the browser to fetch high-priority resources sooner. - Optimize images: Compress, use modern formats (WebP, AVIF), and responsive images.
- Minimize render-blocking resources: Reduce or defer CSS and JavaScript that prevent the page from rendering quickly.
Let's see an example of preloading a hero image:
<!DOCTYPE html>
<html>
<head>
<title>LCP Preload Demo</title>
<!-- Preload the hero image to fetch it early -->
<link rel="preload" href="https://via.placeholder.com/800x450.webp" as="image">
<style>
body { margin: 0; font-family: sans-serif; }
img { max-width: 100%; height: auto; display: block; }
h1 { padding: 10px; }
</style>
</head>
<body>
<h1>Welcome to Our Site!</h1>
<!-- The actual image will render faster due to preload -->
<img src="https://via.placeholder.com/800x450.webp" alt="Important Hero Image" width="800" height="450">
<p>This image is likely the LCP element. Preloading helps it appear faster.</p>
</body>
</html>First Input Delay (FID)
First Input Delay (FID) measures the time from when a user first interacts with a page (e.g., clicks a button, taps a link) to when the browser is actually able to begin processing that interaction.
It's about responsiveness and how quickly your page reacts to user input. It doesn't measure the event handler execution time, only the delay before it can start.
- A good FID score is 100 milliseconds or less.
- Anything above 300 milliseconds is considered poor.
Why FID is High: Busy Main Thread
A high FID often means the browser's main thread is busy doing other work, typically executing JavaScript, and can't respond to user input immediately.
Common causes include:
- Long JavaScript tasks: Heavy scripts that run for an extended period, blocking the main thread.
- Large JavaScript bundles: More code means more time to parse, compile, and execute.
- Third-party scripts: Ads, analytics, or other external scripts can consume significant main thread time.
Optimizing FID: Freeing the Main Thread
To improve FID, you need to reduce the amount of time the main thread is blocked. Here's how:
- Break up long tasks: Divide large JavaScript operations into smaller, asynchronous chunks.
- Defer or async non-critical JS: Use
deferorasyncattributes for scripts that aren't essential for initial rendering. - Reduce JavaScript payload: Minify, tree-shake, and code-split your JavaScript bundles.
- Use Web Workers: Offload computationally intensive tasks to a background thread, keeping the main thread free.
Cumulative Layout Shift (CLS)
Cumulative Layout Shift (CLS) measures the visual stability of a page. It quantifies how much unexpected layout shifts occur during the page's lifespan.
An unexpected shift happens when a visible element changes its start position from one rendered frame to the next. This can be very frustrating for users!
- A good CLS score is 0.1 or less.
- Anything above 0.25 is considered poor.
Common Causes of CLS
Layout shifts often happen when content loads or changes dynamically without reserving space. Key culprits include:
- Images or videos without dimensions: The browser doesn't know how much space to reserve until the media loads.
- Dynamically injected content: Ads, banners, or widgets that appear after the page has started rendering.
- Web Fonts causing FOIT/FOUT: Fonts loading late can cause text to reflow or disappear/reappear.
- Actions waiting for a network response: Content that shifts after an API call completes.
Optimizing CLS: Stable Layouts
Preventing CLS is all about reserving space and ensuring elements don't unexpectedly move. Here are some techniques:
- Specify image/video dimensions: Always use
widthandheightattributes, or CSSaspect-ratio. - Reserve space for ads/embeds: Use CSS
min-heightor a placeholder element. - Avoid inserting content above existing content: Especially after initial page render.
- Preload fonts & use
font-display: Usefont-display: optionalorswapto manage font loading behavior.
Here's an example of how setting image dimensions prevents CLS:
<!DOCTYPE html>
<html>
<head>
<title>CLS Prevention Demo</title>
<style>
body { font-family: sans-serif; }
.container { width: 300px; margin: 20px auto; border: 1px solid #ccc; padding: 10px; }
img { max-width: 100%; height: auto; display: block; margin-bottom: 10px; }
</style>
</head>
<body>
<div class="container">
<p>This content is stable.</p>
<!-- Image with specified width and height prevents layout shift -->
<img src="https://via.placeholder.com/300x200" alt="Placeholder" width="300" height="200">
<p>The content below the image does not jump around.</p>
</div>
</body>
</html>Core Web Vitals Check
Let's test your understanding of Core Web Vitals and their optimization techniques.
Recap: LCP, FID, CLS
You've successfully dived deep into the Core Web Vitals!
- LCP (Largest Contentful Paint): Measures perceived load speed, focusing on the largest content element. Optimize by preloading, optimizing images, and reducing server response time.
- FID (First Input Delay): Measures interactivity, focusing on the delay before the browser responds to user input. Optimize by minimizing and breaking up JavaScript tasks.
- CLS (Cumulative Layout Shift): Measures visual stability. Optimize by reserving space for dynamic content, specifying image dimensions, and managing font loading.
By understanding and improving these metrics, you contribute to a much better user experience!
자주 묻는 질문
“LCP, FID, CLS 심층 분석” 강의는 무료인가요?
네 — “LCP, FID, CLS 심층 분석” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Web Performance Optimization & Lighthouse 강의 전체를 잠금 해제할 수 있습니다. Web Performance Optimization & Lighthouse 강의에는 총 4개의 강의가 포함되어 있습니다.
“LCP, FID, CLS 심층 분석”에서 뭘 배우나요?
Largest Contentful Paint(LCP), First Input Delay(FID), Cumulative Layout Shift(CLS)를 자세히 분석하고 최적화 기법을 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 Web Performance Optimization & Lighthouse을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Web Performance Optimization & Lighthouse을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Web Performance Optimization & Lighthouse은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“LCP, FID, CLS 심층 분석” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Web Performance Optimization & Lighthouse 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Web Performance Optimization & Lighthouse 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 핵심 웹 바이털 소개
- LCP, FID, CLS 심층 분석
- 사용자 상호작용 지표 개선
- 다음 페인트까지의 상호작용(INP)