0
0
NextJSframework~20 mins

Font optimization and self-hosting in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Font Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered font style when using Next.js built-in font optimization with a self-hosted font?

Consider a Next.js app that uses the next/font/local to load a self-hosted font with font optimization enabled. What will be the visible effect on the page's text?

NextJS
import localFont from 'next/font/local';

const myFont = localFont({
  src: './fonts/MyFont.woff2',
  display: 'swap',
});

export default function Home() {
  return <main className={myFont.className}>Hello World</main>;
}
AThe text uses the self-hosted font with a fallback font until the font loads, then swaps to the custom font.
BThe text immediately shows invisible content until the font fully loads, then appears with the custom font.
CThe text uses the system default font and never switches to the self-hosted font.
DThe text uses the self-hosted font but does not apply any fallback font during loading.
Attempts:
2 left
💡 Hint

Think about the display: 'swap' option and how it affects font loading behavior.

📝 Syntax
intermediate
2:00remaining
Which code snippet correctly imports and uses a Google font with Next.js font optimization?

Identify the correct way to import and apply the Inter font from Google Fonts using Next.js built-in font optimization.

A
import { Inter } from 'next/font/google';
const inter = Inter('latin');
export default function Page() {
  return &lt;div className={inter.className}&gt;Text&lt;/div&gt;;
}
B
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ['latin'] });
export default function Page() {
  return &lt;div className={inter.className}&gt;Text&lt;/div&gt;;
}
C
import Inter from 'next/font/google';
const inter = Inter({ subsets: ['latin'] });
export default function Page() {
  return &lt;div className={inter.className}&gt;Text&lt;/div&gt;;
}
D
import { Inter } from 'next/font/google';
const inter = Inter({ weights: ['400'] });
export default function Page() {
  return &lt;div className={inter.className}&gt;Text&lt;/div&gt;;
}
Attempts:
2 left
💡 Hint

Check the correct import syntax and the expected options object for subsets.

🔧 Debug
advanced
2:00remaining
Why does the self-hosted font not apply styles in this Next.js component?

Given this code, the custom font does not appear on the page. What is the most likely cause?

NextJS
import localFont from 'next/font/local';

const myFont = localFont({
  src: './fonts/CustomFont.woff2',
});

export default function Home() {
  return <div className={myFont.className}>Hello</div>;
}
AThe component must wrap the text in a <span> for the font class to apply.
BThe font file format '.woff2' is not supported by Next.js font optimization.
CThe localFont function requires a 'weight' property to apply styles.
DThe font file path is incorrect; it should not include 'public' because Next.js serves 'public' as root.
Attempts:
2 left
💡 Hint

Remember how Next.js handles the public folder for static assets.

state_output
advanced
2:00remaining
What is the effect on page load performance when using Next.js font optimization with Google Fonts?

When you import Google Fonts using Next.js built-in font optimization, what happens to the font loading and page performance?

AFonts are preloaded and inlined in CSS, reducing layout shifts and improving performance.
BFonts are loaded via external Google CDN links, causing slower page loads.
CFonts are bundled with JavaScript, increasing JS bundle size and slowing rendering.
DFonts are downloaded only after the page fully loads, causing invisible text initially.
Attempts:
2 left
💡 Hint

Think about how Next.js optimizes font loading to improve user experience.

🧠 Conceptual
expert
3:00remaining
Which statement best describes the difference between self-hosted fonts and Google Fonts in Next.js font optimization?

Choose the most accurate description of how Next.js handles self-hosted fonts versus Google Fonts with its font optimization feature.

AGoogle Fonts must be downloaded and stored locally, whereas self-hosted fonts are fetched from Google CDN automatically.
BBoth self-hosted and Google Fonts require manual CSS @font-face declarations in Next.js for optimization.
CSelf-hosted fonts require manual file management and local paths, while Google Fonts are automatically fetched and optimized by Next.js with zero config.
DNext.js does not support font optimization for self-hosted fonts, only for Google Fonts.
Attempts:
2 left
💡 Hint

Consider how Next.js manages font files and optimization differently for these two sources.