To optimize images in Next.js, first give each image the correct dimensions and responsive sizes, then decide whether the built-in Image Optimization API or an external image service should generate the image variants. Use a custom loader when an external service should handle transformations; the loader builds a URL from the source, requested width, and quality. The exact options vary by Next.js version, so check the documentation for the version installed in your project.
Start with responsive layout and image dimensions
Use next/image with meaningful alternative text and either intrinsic dimensions or a deliberate responsive fill layout. The width and height values describe the source aspect ratio and help reserve space while an image loads; CSS still determines its rendered size. Next.js explains that these attributes help avoid layout shift.
import Image from 'next/image'
export function ArticleImage() {
return (
<Image
src="/article.jpg"
alt="A person cycling along a coastal road"
width={1600}
height={900}
sizes="(max-width: 768px) 100vw, 50vw"
style={{ width: '100%', height: 'auto' }}
/>
)
}
The example’s sizes value is illustrative, not universal. It says that the image is expected to occupy the full viewport width at widths up to 768 pixels and half the viewport width above that. Match these conditions and proportions to the actual CSS layout. For a responsive image, sizes helps the browser choose a suitable candidate from the generated srcset. Without it, the browser may assume the image is viewport-wide and download a larger candidate than the layout needs. See the Next.js Image Component documentation and the Pages Router Image reference.
Using fill
With fill, the image fills its positioned parent rather than taking an intrinsic width and height. Give the parent a defined layout size and positioning context, and choose whether the image should crop or fit inside that box.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- ULTRA HD 4K CLARITY: Stand out in every video call with breathtaking 4K video at 30fps or smooth 1080p at 60fps. Powered by a premium 1/2.5" CMOS sensor and a wide f/1.78 aperture, this webcam captures every detail with vibrant color and stunning low-light performance-so you always look your best
- FAST AUTOFOCUS & SMART LIGHT CORRECTION: No more blurry moments with this webcam for PC. Advanced Phase Detection Auto Focus (PDAF) locks onto your face instantly and keeps you sharp-even when you move. Built-in light correction adapts to your environment, balancing brightness and contrast for a flawless image in dim rooms or bright spaces
- DUAL NOISE-CANCELING MICS: Speak with confidence using this webcam with microphones. Dual microphones with intelligent noise-canceling tech isolate your voice and reduce background noise-suitable for webinars, live streams, team meetings, and virtual interviews
- WIDE-ANGLE LENS & FLEXIBLE MOUNTING OPTIONS: Capture more of your world with an 80 field of view and full 360 swivel rotation. Whether this streaming webcam is mounted on a laptop, monitor, or tripod, it allows you to find the right angle for any setup
- BUILT-IN PRIVACY COVER & PLUG-AND-PLAY SIMPLICITY: Protect your privacy with a secure sliding lens cover that blocks the camera when not in use. Setup is a breeze-just plug into any USB-A port and start streaming, chatting, or recording instantly. The USB webcam is compatible with Zoom, Microsoft Teams, Skype, OBS Studio, and all major platforms across Windows, macOS, and Linux
<div className="hero">
<Image
src="/hero.jpg"
alt="A mountain ridge at sunrise"
fill
sizes="(max-width: 768px) 100vw, 50vw"
style={{ objectFit: 'cover' }}
/>
</div>
.hero {
position: relative;
aspect-ratio: 16 / 9;
}
objectFit: 'cover' fills the box by cropping any overflow; use contain when the full image should remain visible, accepting any unused space. Adjust sizes to describe the width this box actually occupies at each breakpoint.
How do I use a custom loader with next/image?
A loader is a URL-building function. Next.js supplies the source, requested width, and optional quality; your function returns a URL in the format expected by the image service. The function does not itself perform image transformations or configure the external service.
Use a loader for one image
import Image from 'next/image'
const imageLoader = ({ src, width, quality }) => {
return makeProviderUrl({
src,
width,
quality: quality ?? 75,
})
}
export function ProductImage() {
return (
<Image
loader={imageLoader}
src="/products/shoe.jpg"
alt="Running shoe in blue"
width={1200}
height={800}
sizes="(max-width: 768px) 100vw, 33vw"
/>
)
}
makeProviderUrl is deliberately provider-specific pseudocode, not a runnable integration. Replace it with the selected provider’s documented URL construction. Check how that provider expects the source to be encoded and how it handles allowed hosts, requested widths, quality, output formats, and transformations. The official Next.js loader example uses quality 75 when quality is omitted; confirm defaults and behavior against the installed version and chosen service.
Configure a loader for the project
For app-wide behavior, set images.loader to 'custom' and point images.loaderFile to a module relative to the project root. That file exports the default loader function.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
- 【Efficient Quad-Core Performance】 Powered by a 1.8GHz Quad-Core processor, this mini laptop ensures smooth multitasking. With 2GB RAM and 64GB ROM (expandable to 1TB), it handles daily work and online tasks with ease.
- 【10.1" HD IPS Display & GMS Support】 Featuring a 1280x800 HD IPS screen, this cheap laptop delivers vibrant visuals. Pre-installed with Android OS and GMS, you get direct access to the Google Play Store for apps.
- 【Ultra-Portable & Lightweight Design】 Weighing only 1.76 lbs, this Blue computer is designed for mobility. Its compact form makes it an ideal companion for students and professionals for home schooling or trips.
- 【Versatile Connectivity Options】 Stay productive with dual USB 2.0 ports, a headphone jack, and a TF card slot. This computer for kids and adults features built-in Wi-Fi and Bluetooth for stable connections.
- 【Complete All-in-One Bundle】 This kid laptop kit includes the laptop, carrying bag, mouse, mouse pad, and power adapter. It is the perfect ready-to-use set for online classes, remote work, and entertainment.
// next.config.js
module.exports = {
images: {
loader: 'custom',
loaderFile: './src/lib/image-loader.js',
},
}
// src/lib/image-loader.js
export default function imageLoader({ src, width, quality }) {
return makeProviderUrl({ src, width, quality: quality ?? 75 })
}
The provider URL function remains an integration you must implement. Consult the Next.js image configuration reference alongside the selected service’s documentation.
Built-in optimization or an external image service?
The default Next.js loader uses the Image Optimization API. A custom loader is the documented route when you want an external optimization service or image CDN to generate transformed image URLs. The right choice depends on deployment and source requirements; Next.js documentation establishes the integration route, not the features or costs of a particular provider.
| Decision point | Built-in Next.js optimizer | Custom loader and external service |
|---|---|---|
| Who generates image variants? | Next.js Image Optimization API | The external service addressed by the returned URL |
| URL behavior | Handled by Next.js configuration and its optimizer | Your loader must construct URLs in the provider’s documented syntax |
| Transformation support | Use the capabilities documented for your installed Next.js version | Depends on the provider and the transformations you encode in URLs |
| Cache and invalidation | Next.js optimizer cache behavior applies | Depends on the external service’s cache and invalidation behavior |
| Operational responsibility | Fits the Next.js deployment’s image optimization setup | Requires configuring, reaching, and maintaining the external service integration |
Before choosing, verify the service’s accepted widths and qualities, source-access rules, format negotiation, cache policy, and any costs that apply to your deployment. Those details are provider-specific. For the built-in optimizer’s format and cache behavior, see the Image Component API documentation.
How do I use a remote image with next/image?
When the built-in optimizer fetches remote sources, allow only the URL patterns your application needs. Configure remotePatterns with the expected protocol, hostname, path, and an intentional search-string policy. Avoid broad patterns: the Next.js documentation warns they can permit URLs that were not intended.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #3
- Webcam comes with a 3-month XSplit VCam license and no privacy shutter. XSplit VCam lets you remove, replace and blur your background without a Green Screen.
- Full HD 1080p video calling and recording at 30 fps - You’ll make a strong impression when it counts with crisp, clearly detailed and vibrantly colored video.
- Stereo audio with dual mics - Capture natural sound on calls and recorded videos.
- Custom three-capsule array: This professional USB mic produces clear, powerful, broadcast-quality sound for YouTube videos, Twitch game streaming, podcasting, Zoom meetings, music recording and more
- Blue VOICE software: Elevate your streamings and recordings with clear broadcast vocal sound and entertain your audience with enhanced effects, advanced modulation and HD audio samples
// next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.example.com',
pathname: '/account123/**',
search: '',
},
],
},
}
Replace the example host and path with the precise remote source you trust, and check the supported configuration syntax for your installed Next.js version. The default optimizer does not forward request headers when fetching an image. If the source requires authentication headers, the documentation advises considering unoptimized so the image is served without the optimization fetch.
SVGs are generally served unoptimized. If you enable SVG optimization, follow Next.js’s documented content-disposition and content-security-policy protections rather than treating arbitrary SVG sources as safe.
Format selection and caching in the built-in optimizer
The built-in optimizer selects from configured output formats based on the request’s Accept header. The documented default is WebP; AVIF can also be configured, with encoding and cache tradeoffs described in the Next.js documentation. If a proxy or CDN sits in front of Next.js, it must forward Accept for format negotiation to work as expected.
minimumCacheTTL sets a lower bound for the optimizer cache lifetime; the upstream image’s cache-control value can make the effective max age longer. The documentation states that there is no cache invalidation mechanism. If an image may change, avoid relying on a long cache lifetime for a URL that stays the same; use a changed source URL or clear the image cache when appropriate. These details apply to the built-in optimizer, not automatically to custom-loader providers.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsRank #4
- Compatible with Logitech C920x HD Pro Webcam, Full HD 1080p/30fps Video Calling. Compatible with Logitech C920 Hd Pro Webcam. Compatible with Logitech HD Pro Webcam C920 Widescreen Video Calling and Recording Webcam.
- Compatible with Logitech C930e Webcam. Compatible with Logitech C922 Pro Stream Webcam 1080P Camera for HD Video Streaming. Compatible with Logitech Privacy Cover for C920 and C930e.
- This webcam cover conveniently blocks your camera cover to protect your privacy.
- This also compatible with other popular webcams. This is also known as webcam lid, webcam cap, webcam protector, web camera privacy cover.
- ienza is a registered trademark and a registered Amazon brand. Use of the ienza trademark without the prior written consent of ienza, LLC. may constitute trademark infringement and unfair competition in violation of federal and state laws. ienza products are developed as cost-effective alternatives to OEM parts. They are not necessarily endorsed by the OEMs
When should I preload an image?
Preload only when you know which above-the-fold image is likely to be the page’s Largest Contentful Paint (LCP) image. If that is not clear—for example, because the hero image changes with viewport—preloading candidates can waste bandwidth. The Pages Router reference notes that loading="eager" or fetchPriority="high" may be preferable in most cases. Follow the API supported by your installed version and coordinate preload with other loading or fetch-priority controls.
Troubleshooting image optimization
- The image is too large or slow to download: Check that
sizesmatches the rendered CSS width at each breakpoint, especially withfill. Inspect the generatedsrcsetand selected candidate in the browser. - The image causes layout shift: For intrinsic images, provide accurate
widthandheightvalues. Forfill, ensure the parent has a defined size and positioning context before the image loads. - A remote image is rejected: Verify that its protocol, hostname, path, and search policy match
remotePatterns. Narrowly configure the expected source rather than broadly allowing remote URLs. - An authenticated image fails through the default optimizer: The optimizer does not forward request headers to the source. Consider the documented
unoptimizedoption or a service integration designed for the source’s access requirements. - A custom-loader URL is invalid or returns an unexpected image: Check the provider’s URL syntax, source encoding, supported widths and quality values, host restrictions, and format behavior. A loader only constructs the URL; it cannot make an unavailable or incompatible service work.
- The output format does not change as expected: For the built-in optimizer, confirm that the format is configured and that any proxy or CDN forwards the browser’s
Acceptheader. With a custom loader, verify format selection with the provider. - Updated source content remains stale: Built-in optimizer caching has no invalidation mechanism. Change the source URL or clear the image cache as appropriate; external-provider cache controls are provider-specific.
- Preloading competes with more important resources: Preload only the known likely LCP image, and avoid combining it indiscriminately with eager loading or high fetch priority.
Or skip the browser setup
If you need screenshots of pages rather than optimized images inside a Next.js site, ScreenshotNeo is a screenshot API and MCP server. One GET request returns an image or PDF; cookie banners, newsletter popups, and chat widgets are removed before capture, and bot checks, blank pages, and failed loads are not billed. AI agents can capture pages through its MCP server. It includes 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000.
cURL example, using the documented API endpoint and syntax:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for setup and options. Sign up for 1,000 free screenshots a month with no card.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

