Image Optimization in Next.js – Local and Remote Images with the <Image> Component

Next.js provides a powerful <Image> component that extends the native <img> element with built-in optimization features. This article explores how to use the component for local and remote images, prevent layout shifts, enable lazy loading, and configure remote image domains securely.

Next.js ImageImage OptimizationLazy LoadingRemote ImagesBlur Placeholder

~2 min read · Updated Oct 25, 2025

Why Use the <Image> Component?


The next/image component enhances the standard <img> tag with built-in optimizations:

  • Size optimization: Automatically serves the best image size and format (e.g., WebP) for each device.
  • Visual stability: Prevents layout shifts by reserving space before the image loads.
  • Lazy loading: Loads images only when they enter the viewport, improving performance.
  • Blur placeholders: Optionally show a low-quality preview while the full image loads.
  • Remote support: Resize and optimize images hosted on external servers.

Getting Started


Import the component from next/image and use it in your component:

import Image from 'next/image'

export default function Page() {
  return <Image src="" alt="" />
}

Using Local Images


Place your images inside the /public directory. Then reference them using a relative path from the root:

<Image
  src="/profile.png"
  alt="Picture of the author"
  width={500}
  height={500}
/>

Static Imports


When importing images statically, Next.js automatically infers width, height, and blur placeholder:

import ProfileImage from './profile.png'

<Image
  src={ProfileImage}
  alt="Picture of the author"
  placeholder="blur"
/>

Using Remote Images


You can also use external image URLs:

<Image
  src="https://s3.amazonaws.com/my-bucket/profile.png"
  alt="Picture of the author"
  width={500}
  height={500}
/>

Since remote images aren’t available at build time, you must manually provide width and height to avoid layout shifts. You can also use fill to make the image fill its parent container.


Allowing Remote Domains


To safely use remote images, define allowed domains in next.config.ts:

// next.config.ts
import type { NextConfig } from 'next'

const config: NextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 's3.amazonaws.com',
        pathname: '/my-bucket/**',
      },
    ],
  },
}

export default config

Tip: Be specific with remote patterns to avoid security risks.


Conclusion


The <Image> component in Next.js offers a modern, performance-first approach to image handling. Whether you're working with local assets or remote URLs, it ensures fast loading, visual stability, and responsive behavior across devices.


Written & researched by Dr. Shahin Siami

Related Articles

Advanced Client-Side Routing and Performance Hooks in Next.js

Next.js provides a rich set of client-side hooks and caching utilities that empower developers to build dynamic, responsive, and secure applications. From reading route parameters to tracking navigation state and reporting performance metrics, this guide walks you through the most important tools available in the App Router.

Continue

Handling Authorization and Caching in Next.js: A Developer’s Guide

Next.js introduces powerful experimental features for access control and smart caching. This guide covers the unauthorized() function for custom 401 handling, unstable_cache for persistent memoization, updateTag for instant cache invalidation, and useLinkStatus for inline navigation feedback. Learn how to use these tools to build secure, performant, and responsive applications.

Continue

redirect and refresh in Next.js — Smart Redirects and Client Refreshing via Server Actions

The redirect function in Next.js allows you to navigate users to a new route, returning either a 307 or 303 HTTP response depending on context. It works in Server Components, Client Components, Route Handlers, and Server Actions. The refresh function is used exclusively within Server Actions to refresh the client router. This article explains how both functions work, with practical examples and key considerations.

Continue

NextRequest and NextResponse in Next.js — Managing Cookies, Headers, Redirects, and Rewrites

Next.js extends the native Web Request and Response APIs with NextRequest and NextResponse, offering powerful tools for managing cookies, headers, redirects, rewrites, and JSON responses. These utilities simplify server-side logic and improve control over routing, personalization, and security. This guide walks through their capabilities with practical examples and best practices.

Continue

headers, ImageResponse, notFound, and permanentRedirect in Next.js — Request Handling, Dynamic Images, Errors, and Redirects

Next.js offers powerful tools for handling HTTP requests and responses in Server Components. The headers function lets you read incoming request headers. ImageResponse allows you to generate dynamic images using JSX and CSS. The notFound function renders a custom 404 page, and permanentRedirect enables permanent redirection to another route. This article explains how to use each feature with practical examples.

Continue

A Complete Guide to Using metadata and generateMetadata in Next.js

In modern versions of Next.js, managing page metadata is more powerful and intuitive than ever. Metadata is automatically injected into the <head> of your pages and plays a vital role in SEO, social sharing, and user experience. This guide explains the two main ways to define metadata: using the static metadata object and the dynamic generateMetadata function.

Continue