Image & Font Optimization
5 questions found
What does the built-in Image component in Next.js do differently from a regular HTML img tag?
Beginner
The Image component automatically resizes images to fit the size they are displayed at, serves modern efficient formats like WebP when supported, lazy loads images that are not yet visible on screen, and prevents layout shift by reserving the correct amount of space before the image finishes loading.
import Image from 'next/image';
export default function Avatar() {
return <Image src="/profile.jpg" alt="User profile picture" width={100} height={100} />;
}
Real-world example
A photography portfolio site uses the Image component for every photo, dramatically reducing page load times since images are automatically resized and served in efficient modern formats.
Common follow-ups: Why do you need to specify width and height on the Image component?;What happens if an image's actual size on the page changes based on screen size?
Web Vitals & Performance Monitoring;Bundle Analysis & Code Splitting
How do you optimize custom fonts in a Next.js application using next/font?
Beginner
The next/font module lets you import fonts, including Google Fonts, directly into your project, automatically hosting the font files alongside your application and eliminating extra network requests to external font providers, while also preventing layout shift caused by fonts loading late.
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ['latin'] });
export default function Layout({ children }) {
return <html className={inter.className}><body>{children}</body></html>;
}
Real-world example
A company website switches to next/font for its Google Font, removing a noticeable flash of unstyled text and speeding up the page since the font no longer needs a separate external request.
Common follow-ups: Does next/font work with fonts other than Google Fonts?;How does next/font help improve a website's Core Web Vitals scores?
Web Vitals & Performance Monitoring;Metadata API & SEO Optimization
How does the Image component handle responsive images that need to look good on different screen sizes?
Intermediate
You use the sizes prop along with fill or a responsive width and height, telling the browser roughly how large the image will be displayed at different screen widths, allowing Next.js to generate and serve the most appropriately sized version of the image for each device.
<Image
src="/hero.jpg"
alt="Hero banner"
fill
sizes="(max-width: 768px) 100vw, 50vw"
style={{ objectFit: 'cover' }}
/>
Real-world example
A news website serves a smaller version of its hero image to mobile phone visitors and a larger version to desktop visitors, all automatically handled by the Image component based on the sizes prop.
Common follow-ups: What is the difference between using the fill prop and specifying explicit width and height?;How do you handle images that come from an external domain?
Web Vitals & Performance Monitoring;Third-Party Script Optimization
How do you configure Next.js to allow optimizing images that are hosted on an external domain?
Intermediate
You add the external domain's hostname to the images configuration inside your next.config.js file, since Next.js only optimizes images from domains you explicitly trust, preventing it from being used to proxy and optimize arbitrary images from anywhere on the internet.
// next.config.js
module.exports = {
images: {
remotePatterns: [
{ protocol: 'https', hostname: 'images.example.com' }
]
}
};
Real-world example
An online store fetching product images from a separate content delivery network adds that domain to its Next.js configuration, allowing the Image component to properly optimize those external images.
Common follow-ups: What happens if you try to use an external image domain that has not been configured?;Is there a performance cost to optimizing many external images?
Next.js Project Setup & Configuration;Security Best Practices in Next.js
What strategies help further improve loading performance for image heavy pages beyond the default Image component behavior?
Advanced
You can mark the most important above the fold image with the priority prop so it loads immediately without lazy loading, use a blur placeholder to show a low quality preview while the full image loads, and carefully choose appropriate sizes and formats to avoid sending unnecessarily large images to smaller screens.
<Image
src="/hero.jpg"
alt="Main banner"
width={1200}
height={600}
priority
placeholder="blur"
blurDataURL="data:image/jpeg;base64,..."
/>
Real-world example
A landing page marks its large hero image with the priority prop so it loads immediately rather than being lazy loaded, improving how quickly visitors see the most important visual content.
Common follow-ups: What is the largest contentful paint metric and how does image optimization affect it?;When should you avoid using the priority prop?
Web Vitals & Performance Monitoring;Rendering (SSR/SSG/ISR)