Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify preload fetch priority #989

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions playground/pages/provider/[provider].vue
Original file line number Diff line number Diff line change
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
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 @@ -94,6 +94,9 @@ export default defineComponent({
imagesizes: sizes.value.sizes,
imagesrcset: sizes.value.srcset,
}),
...(typeof props.preload !== 'boolean' && props.preload.fetchPriority
? { fetchpriority: props.preload.fetchPriority }
: {}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we default to fetchpriority: 'high'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not answering in time, this comment fell off my radar 🌠

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still time to update - what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should the fetch priority default to high in your opinion? I'd say we can just leave it for the users to decide if they want to specify any.

}],
})
}
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 @@ -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 }
danielroe marked this conversation as resolved.
Show resolved Hide resolved
: {}),
}

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