I'd like to load pictures from other domain that is "api.domain.com".
I have configured next.config.js like this in order to avoid external URL error.
const nextConfig = {
images: {
remotePatterns: [
{
protocol: "http",
hostname: "api.example.app",
port: ""
}
]
}
}
But when I inspect image what I see is that it's setting srcset="/_next/image?url=http://example.com/assets/photo.png"
How can I bypass adding _next/image as prefix?
P.s please do not recommend me using img tag.
Next.js automatically optimize images when you use
<Image />fromnext/image.Let's say you have a
.pngimage with 1MB size, and its source ishttp://example.com/assets/photo.png. Next.js will generate some variants of the image with more modern formats e.g..webpin different sizes, 0.1 MB, 0.5 MB, and 1 MB. it will collect anysrcyou passed to<Image />(and exists in theremotePatterns) to change thesrcto the Next.js built-in optimization loader/_next/image?url=${src}. This way it will respond with the suitable image variant for the device.Reed more: https://nextjs.org/docs/app/building-your-application/optimizing/images
You can make your custom loader: https://nextjs.org/docs/app/api-reference/components/image#loader