React / Next.js

Next.js Advanced Features

Image optimization, Font optimization, Script optimization, analytics, edge runtime, experimental features

24 interview questionsยท
Senior
1

What is the main advantage of using next/image compared to a standard img tag?

Answer

next/image automatically optimizes images by generating multiple sizes and modern formats (WebP, AVIF), applies lazy loading by default, and improves Web Vitals by preventing Cumulative Layout Shift through automatic dimension calculation. Unlike a standard img tag that loads the original image, next/image serves the optimal size based on viewport and device pixel ratio. This approach significantly reduces loading time and bandwidth consumption.

2

When to use the priority property on a next/image component?

Answer

The priority property disables lazy loading and preloads the image immediately, which is crucial for above-the-fold images that impact Largest Contentful Paint (LCP). Without priority, these critical images would be lazy loaded, delaying LCP and degrading Core Web Vitals. Use priority only for 1-2 images visible on initial page load, typically hero images or main banners.

3

Which next/image configuration allows serving images from an external domain?

Answer

The remotePatterns property in next.config.js allows defining authorized external domains for serving images, with granular control over protocol, hostname, port and pathname. This approach replaces the deprecated domains property and offers enhanced security by precisely limiting authorized sources. Configuring remotePatterns prevents 400 errors when loading images hosted on CDNs or third-party services like Cloudinary or AWS S3.

4

What is the difference between fill and responsive for next/image sizing?

5

How to optimize static images imported locally with next/image?

+21 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free