Skip to content

Commit

Permalink
feat: allow to specify preload fetch priority
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Apr 17, 2024
1 parent e1e1c81 commit 0a09d14
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion playground/pages/provider/[provider].vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br>
<div class="providerShowcase">
<div v-for="sample of provider.samples" :key="sample.src">
<nuxt-img :provider="provider.name" v-bind="sample" />
<nuxt-img :provider="provider.name" v-bind="sample" :preload="{ fetchPriority: 'auto' }" />
<pre>{{ sample }}</pre>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/components/_base.ts
Original file line number Diff line number Diff line change
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
5 changes: 4 additions & 1 deletion src/runtime/components/nuxt-img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export default defineComponent({
href: sizes.value.src,
imagesizes: sizes.value.sizes,
imagesrcset: sizes.value.srcset
})
}),
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {})
}]
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/components/nuxt-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export default defineComponent({
rel: 'preload',
as: 'image',
imagesrcset: sources.value[0].srcset,
nonce: props.nonce
nonce: props.nonce,
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {})
}

if (sources.value?.[0]?.sizes) { link.imagesizes = sources.value[0].sizes }
Expand Down

0 comments on commit 0a09d14

Please sign in to comment.