Difference between importing or using a path for loading images?
Unanswered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
Hello, I have an image called
What's the difference between loading in these two different ways? Is there a recommended one?
I understand that the final result is an
1. Through importing
2. Through path reference
avatar.png inside my public/ folder.What's the difference between loading in these two different ways? Is there a recommended one?
I understand that the final result is an
<img> element, and for the first way it loads the image from a the nextjs static folder and the second way loads directly from the public folder, but I still don't know which is best and what's the rule of thumb.1. Through importing
import avatarPng from '@/public/avatar,png';
<Image src={avatarPng} />2. Through path reference
<Image src="/avatar.png" width="50" height="50" />2 Replies
Northeast Congo LionOP
For reference the second way is described here https://nextjs.org/docs/app/building-your-application/optimizing/static-assets
And the first way described here: https://nextjs.org/docs/app/building-your-application/optimizing/images#local-images