Demo Site: Load mobile image in BasicStageBlock with priority#3743
Demo Site: Load mobile image in BasicStageBlock with priority#3743
Conversation
| <Root> | ||
| <MediaPhone> | ||
| <MediaBlock data={media} aspectRatio="1x2" fill /> | ||
| <MediaBlock data={media} aspectRatio="1x2" fill priority /> |
There was a problem hiding this comment.
this only sets priority for MediaPhone breakpoint, and I'm assuming it does that for all device widths?
There was a problem hiding this comment.
The problem here is: If you set priority for all four device widths, all four image versions are always loaded. This results in three unnecessary image loads (especially problematic on mobile).
I think the idea here is to just preload the mobile version to be fast on mobile devices. And on desktop it's usually no problem to also load the mobile image.
There was a problem hiding this comment.
(But it's kind of confusing, you are right)
There was a problem hiding this comment.
(But it's kind of confusing, you are right)
that is not my problem at all
we could do better:
preload link supports media queries. Does react-dom preload work for us?
There was a problem hiding this comment.
And on desktop it's usually no problem to also load the mobile image.
I'm not sure about this. This will show up on all SEO reports.
There was a problem hiding this comment.
preload link supports media queries. Does react-dom preload work for us?
I just had a look at the next/image priority implementation and I believe it's possible, since it's already using react-dom preload. We'd need to specify priority and sizes for all viewports, but then it should work.
There was a problem hiding this comment.
I didn't know about the media attribute in link. That's cool and would solve our problem 👍
Unfortunately, react preload only supports media starting in v19 (facebook/react#28635 (comment))
To date, Next doesn't support media at all (not even in v15 as it looks). So we can't use it.
Regarding a solution with only srcset and sizes: I don't think this always works.
In our example, the stage image always takes up 100vw. Meaning, specifying sizes as 100vw for all breakpoints is correct.
I'm not an expert in defining responsive images and didn't experiment, but according to ChatGPT, Desktop and Mobile can have an overlap in the image sizes they request because the device pixel ratio can be > 1
"Mobile" ≠ Small physical size
A modern phone can have a viewport width of 430px but a devicePixelRatio of 3, so it needs a 1290px-wide image!"Desktop" ≠ Large image area
If your desktop layout only gives an image 400px of screen space (e.g. in a sidebar), it’ll download an image similar in size to what mobile might use.✅ So YES: Mobile and desktop can easily request the same image size, depending on:
- How big the image appears in your CSS layout
- The device’s pixel density (Retina vs non-Retina)
So only defining srcset and using small sizes for the mobile images and big sizes for Desktop won't work correctly, to my understanding.
There was a problem hiding this comment.
Maybe we can build our own solution that adds a link with the correct media. But I didn't look into that
|
We close this because it's a half-solution. Instead we will fix priority loading for stages in v9 when we update to React 19 so we can use preload as detailed in #3743 (comment) |
Description
The image of the BasicStageBlock displayed at the mobile breakpoint is loaded with priority. This allows Next.js to preload the image and therefore improve the Largest Contentful Paint (LCP) metric.
Acceptance criteria
Screenshots/screencasts
Further information