0Pricing
Web Performance Optimization & Lighthouse · 강의

글꼴 로딩 최적화

`font-display`, 사전 로드, 서브셋을 구현하여 웹 글꼴을 효율적으로 로드하고 레이아웃 이동을 방지합니다.

글꼴 로딩 최적화은(는) CoddyKit의 무료 Web Performance Optimization & Lighthouse 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Web Performance Optimization & Lighthouse 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Web Performance Optimization & Lighthouse 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Optimize Fonts?

Web fonts make websites beautiful and unique, but they can also be a major source of performance bottlenecks. Large font files mean longer download times, which directly impacts your site's overall speed and user experience.

Slow font loading can lead to issues like 'Flash of Unstyled Text' (FOUT) or 'Flash of Invisible Text' (FOIT). In this lesson, we'll learn practical techniques to load fonts efficiently.

Control Font Loading with `font-display`

The font-display CSS property gives you control over how web fonts load and display. It tells the browser what strategy to use while a font is still downloading, helping to prevent jarring visual shifts.

  • auto: The browser's default behavior.
  • block: Short block period (invisible text), then infinite swap.
  • swap: Very short block period (invisible text), then infinite swap.
  • fallback: Very short block, then short swap, then permanent fallback.
  • optional: Very short block, no swap, permanent fallback.

`font-display: swap` in Action

font-display: swap is a popular choice for balancing performance and aesthetics. It tells the browser to use a fallback font immediately. Once your custom web font is downloaded, it 'swaps' in, replacing the fallback.

This ensures text is always visible, prioritizing content readability over font styling during the initial load.

@font-face {
  font-family: 'MyWebFont';
  src: url('mywebfont.woff2') format('woff2');
  font-display: swap;
}

`optional` and `fallback` Strategies

Other font-display values offer different trade-offs:

  • fallback: Gives the custom font a very short block period (around 100ms) and a short swap period (around 3s). If the custom font isn't ready within these times, it uses a fallback font permanently.
  • optional: Similar to fallback, but the browser decides if the custom font is downloaded at all, based on network conditions. If the font is not downloaded quickly, the fallback is used permanently, avoiding any layout shift.

Preloading Critical Fonts

Normally, browsers discover fonts when they parse your CSS. However, you can tell the browser to fetch a resource *earlier* than it would normally discover it using preloading.

For fonts, <link rel="preload"> means the browser can start downloading them even before the CSS that uses them is fully parsed. This significantly reduces the time until text is displayed with the correct font.

How to Preload a Font

You can preload fonts by adding a <link> tag in your HTML's <head> section. It's crucial to include as="font" and crossorigin to ensure the font is fetched correctly and to prevent double downloads.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Preload Font Example</title>
  <link rel="preload" href="mywebfont.woff2" as="font" type="font/woff2" crossorigin>
  <style>
    @font-face {
      font-family: 'MyWebFont';
      src: url('mywebfont.woff2') format('woff2');
      font-display: swap;
    }
    body {
      font-family: 'MyWebFont', sans-serif;
    }
  </style>
</head>
<body>
  <h1>Hello CoddyKit!</h1>
  <p>This text uses a preloaded web font.</p>
</body>
</html>

Reducing Font Size with Subsetting

Font files often contain hundreds, or even thousands, of characters. Many of these, like special symbols or characters for different languages, might not be used on your specific website.

Font subsetting is the process of creating a smaller version of a font file that only includes the specific characters (glyphs) your website actually needs. This drastically reduces the file size.

Why Subset Your Fonts?

Subsetting has a direct and significant impact on your website's performance:

  • Faster Downloads: Smaller font files download much quicker, leading to improved page load times.
  • Reduced Bandwidth: This saves data for your users, which is especially important for those on mobile plans.
  • Better User Experience: Less waiting means users see your content, styled correctly, much faster.

Tools like Font Squirrel's Webfont Generator or Google Fonts can help you subset.

Test Your Font Knowledge

Which of the following are effective strategies for optimizing web font loading and performance?

Font Loading Recap

We've covered essential techniques for optimizing web font loading:

  • font-display: This CSS property controls how fonts render during download, preventing FOUT and FOIT.
  • Preloading: Using <link rel="preload"> in your HTML fetches critical fonts earlier, speeding up their availability.
  • Subsetting: Reduces font file size by including only the characters your website actually needs.

By applying these strategies, you can significantly improve your website's perceived performance and deliver a smoother user experience.

자주 묻는 질문

“글꼴 로딩 최적화” 강의는 무료인가요?

네 — “글꼴 로딩 최적화” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Web Performance Optimization & Lighthouse 강의 전체를 잠금 해제할 수 있습니다. Web Performance Optimization & Lighthouse 강의에는 총 4개의 강의가 포함되어 있습니다.

“글꼴 로딩 최적화”에서 뭘 배우나요?

`font-display`, 사전 로드, 서브셋을 구현하여 웹 글꼴을 효율적으로 로드하고 레이아웃 이동을 방지합니다. 브라우저에서 직접 실행하는 실습 코드로 Web Performance Optimization & Lighthouse을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Web Performance Optimization & Lighthouse을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Web Performance Optimization & Lighthouse은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“글꼴 로딩 최적화” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Web Performance Optimization & Lighthouse 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Web Performance Optimization & Lighthouse 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 중요 CSS 및 CSS 전달
  2. 글꼴 로딩 최적화
  3. CSS-in-JS의 성능 영향
  4. 사용하지 않는 CSS 줄이기
← Web Performance Optimization & Lighthouse(으)로 돌아가기