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 4b3a044
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 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
3 changes: 3 additions & 0 deletions src/runtime/components/nuxt-img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default defineComponent({
rel: 'preload',
as: 'image',
nonce: props.nonce,
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {}),
...(!isResponsive
? { href: src.value }
: {
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/components/nuxt-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default defineComponent({
rel: 'preload',
as: 'image',
imagesrcset: sources.value[0].srcset,
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {}),
nonce: props.nonce
}

Expand Down

0 comments on commit 4b3a044

Please sign in to comment.