Skip to content

Commit

Permalink
Move to fetchPriority for eagerly loading images instead of using `<l…
Browse files Browse the repository at this point in the history
…ink rel=preload/>`
  • Loading branch information
paales committed Jan 22, 2024
1 parent b3faac6 commit 2a7b22a
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions packages/image/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
height={height}
data-nimg
sx={[style, ...(Array.isArray(sx) ? sx : [sx])]}
fetchPriority={loading === 'eager' ? 'high' : undefined}
/>
) : (
<Picture {...pictureProps}>
Expand All @@ -518,43 +519,10 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
sizes={sizes}
data-nimg
decoding='async'
fetchPriority={loading === 'eager' ? 'high' : undefined}
/>
</Picture>
)}
{loading === 'eager' && (
<Head>
{unoptimized ? (
<link key={`__nimg-unoptimized-${src}`} rel='preload' as='image' href={src} />
) : (
<>
<link
key={`img-${srcSet3x}${sizes}`}
rel='preload'
as='image'
media='(-webkit-min-device-pixel-ratio: 2.5)'
imageSrcSet={srcSet3x}
imageSizes={sizes}
/>
<link
key={`img-${srcSet2x}${sizes}`}
rel='preload'
as='image'
media='(-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.49)'
imageSrcSet={srcSet2x}
imageSizes={sizes}
/>
<link
key={`img-${srcSet1x}${sizes}`}
rel='preload'
as='image'
media='(-webkit-max-device-pixel-ratio: 1.49)'
imageSrcSet={srcSet1x}
imageSizes={sizes}
/>
</>
)}
</Head>
)}
</>
)
},
Expand Down

0 comments on commit 2a7b22a

Please sign in to comment.