Support for media attribute in <NextImage> component for responsive preload control #82472
tomraasowow
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
In responsive designs, it’s common to serve different hero images for desktop and mobile using next/image. However, when priority (which adds rel="preload" links in head) is set to true, both images are preloaded regardless of the device, leading to wasted bandwidth and performance issues.
A typical workaround—dynamically importing the Image component or switching sources client-side—does not prevent both images from being preloaded when marked with priority.
Native HTML allows developers to specify a media attribute on preload links to conditionally load resources. The lack of equivalent support in Next.js leads to a gap in performance optimization.
Proposal
Add support for a media prop on the Image component, which is passed through to the generated link[rel=preload] element when priority is true. For example:
<Image src="/hero-desktop.jpg" priority preloadMedia="(min-width: 769px)" />
Beta Was this translation helpful? Give feedback.
All reactions