5 ms·
>That's what srcset & <source> were invented for. I don't know Next.js but I just spot checked a comparison to see if srcset is an exact subtitute. - If I'm r
by jasode 6y ago
>That's what srcset & <source> were invented for.
I don't know Next.js but I just spot checked a comparison to see if srcset is an exact subtitute.
- If I'm reading CanIUse chart correctly, it says IE11 isn't compatible.[1]
- syntax of srcset requires manual and verbose specification of different source images. E.g. from MDN[2]:
<img srcset="elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="(max-width: 600px) 480px,
800px"
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy">
- Next.js example[3] is simpler and shorter:
import Image from 'next/image'
<Image src="/profile-picture.jpg" width="400" height="400">
The Next.js post also says that <Image> tag also provides the following dynamic feature: When using the next/image component, images are automatically lazy-loaded, meaning they're only rendered when the user is close to seeing the image. This prevents loading that 30% of images outside of the initial viewport.
Like I said, I'm not an expert. The Next.js Image function doesn't look like useless redundancy with plain HTML5.
[1] https://caniuse.com/?search=srcset https://caniuse.com/?search=srcset
[2] https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#Resolution_switching_Different_sizes https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimed...
[3] https://nextjs.org/blog/next-10#nextjs-image-component https://nextjs.org/blog/next-10#nextjs-image-component
- anuila 6y agoYeah, I mean, screw IE11 users. An unsupported srcset just means that they will not benefit from this enhancement but they will just download a standard size. This is perfectly fine. As for the syntax, yes, it’s better to always have some generator to create it. WordPress has been doing it for years with a plain `the_image($id)` call.
- acoard 6y agoA better way of saying this is that srcset gracefully degrades for IE11. They will miss out on the benefits, but they still get to use a regular <img /> tag.
- dbbk 6y agoNext's Image component renders out to the first example. They are ultimately the same thing.