Font & Script Optimization
CONCEPTS:Next.js Font and Script Optimization
Question Variations
- "How does Next.js optimize Google Fonts?"
- "What is the benefit of using `next/font` over a standard CSS `@font-face`?"
- "How would you load a third-party analytics script without blocking the main thread?"
- "What is Cumulative Layout Shift and how do fonts contribute to it?"
Why This Is Asked
Fonts and third-party scripts (like Analytics or Ads) are common causes of slow page loads and layout shifts. Interviewers want to see if you know how to use the framework’s tools to mitigate these performance bottlenecks.
Key Concepts
next/fontand CLS: How the framework handles fallback fonts and size adjustments.- Google Fonts vs Local Fonts: The benefits of self-hosting at build time.
- Script Loading Strategies: When to use
beforeInteractivevslazyOnload. - Inline Scripts: How to safely include scripts using the
Scriptcomponent.
Question Variations
- “How does Next.js optimize Google Fonts?”
- “What is the benefit of using
next/fontover a standard CSS@font-face?” - “How would you load a third-party analytics script without blocking the main thread?”
- “What is Cumulative Layout Shift and how do fonts contribute to it?”