Skip to content

Commit

Permalink
feat: allow specifying fetchpriority when preloading images (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed May 2, 2024
1 parent 5262730 commit b29cb33
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions playground/pages/provider/[provider].vue
Expand Up @@ -11,6 +11,7 @@
<nuxt-img
:provider="provider.name"
v-bind="sample"
:preload="{ fetchPriority: 'auto' }"
/>
<pre>{{ sample }}</pre>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/components/_base.ts
Expand Up @@ -20,7 +20,12 @@ export const baseImageProps = {

sizes: { type: [Object, String] as unknown as () => string | Record<string, any>, default: undefined },
densities: { type: String, default: undefined },
preload: { type: Boolean, default: undefined },
preload: {
type: [Boolean, Object] as unknown as () => boolean | {
fetchPriority: 'auto' | 'high' | 'low'
},
default: undefined,
},

// <img> attributes
width: { type: [String, Number], default: undefined },
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/components/nuxt-img.ts
Expand Up @@ -96,6 +96,9 @@ export default defineComponent({
imagesizes: sizes.value.sizes,
imagesrcset: sizes.value.srcset,
}),
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {}),
}],
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/components/nuxt-picture.ts
Expand Up @@ -64,6 +64,9 @@ export default defineComponent({
as: 'image',
imagesrcset: sources.value[0].srcset,
nonce: props.nonce,
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {}),
}

if (sources.value?.[0]?.sizes) {
Expand Down

0 comments on commit b29cb33

Please sign in to comment.