Optimise images for high-density displays #26065
Closed
jakearchibald
started this conversation in
Ideas
Replies: 2 comments 4 replies
-
Related discussion: #25393 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Update: We have extracted the core logic from This allows usage outside of
Exampleimport { unstable_getImgProps as getImgProps } from 'next/image'
export default function Page() {
const common = { alt: 'Hero', width: 800, height: 400 }
const { props: { srcSet: dark } } = getImgProps({ ...common, src: '/dark.png' })
const { props: { srcSet: light, ...rest } } = getImgProps({ ...common, src: '/light.png' })
return (<picture>
<source media="(prefers-color-scheme: dark)" srcSet={dark} />
<source media="(prefers-color-scheme: light)" srcSet={light} />
<img {...rest} />
</picture>)
} PR: #51205 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you'd like to request
Images on high-density displays can be compressed to a much greater extent without visual loss. Almost every mobile has a high density screen, as does a significant portion of desktop/laptop screens.
Unfortunately, next.js's image element doesn't take advantage of this, as it uses a single
srcset
. This means that the828w
image may be used on high-density mobile screens, but it may also be used on a 1x desktop screen.To look good on a 1x desktop screen, the image needs to be a much higher quality. As a result, mobile users are downloading bigger images (in terms of file size) than necessary, which load slower and use more bandwidth.
Describe the solution you'd like
Allow
<Image />
to serve images using a pattern like this:Where a different set of sources is provided for 1.5x (or whatever cut off you choose) and above vs 1x.
The higher density images would be compressed to a lower 'quality' setting, making them smaller and quicker to download. Since they're displayed on a high density screen, the compression artefacts are not as noticable.
I wrote a blog post about this, with examples https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/.
This may need to be opt-in, since changing from an
<img>
to a<picture>
may not be backwards-compatible with existing site CSS.Describe alternatives you've considered
I guess the alternative is to keep serving unnecessarily large resources to users with high density screens.
Beta Was this translation helpful? Give feedback.
All reactions