Advertisement
Advanced Next.js, Web Vitals & Performance Monitoring

How would you reduce Cumulative Layout Shift on a page that loads ads, images, and web fonts asynchronously?

Short answer

You reserve the correct amount of space for elements before their final content loads, such as setting explicit width and height on images and ad containers, using next/font to avoid a flash of differently sized fallback text, and avoiding inserting new content above existing…

Save Next.js mock interview
Advertisement
AModel answer
You reserve the correct amount of space for elements before their final content loads, such as setting explicit width and height on images and ad containers, using next/font to avoid a flash of differently sized fallback text, and avoiding inserting new content above existing content after the initial page load has already completed.
// Reserve space to prevent layout shift
<div style={{ minHeight: '250px' }}>
  <AdBanner />
</div>
Real-world example
A news website reserves a fixed height for its advertisement slots before the ads actually load, preventing the surrounding article text from jumping around as ads appear, which was previously frustrating readers.
Likely follow-ups
  • What is the maximum layout shift score considered acceptable by web performance standards?
  • How does next/font specifically help reduce layout shift caused by custom fonts?
Related topics