diff --git a/.changeset/gold-maps-promise.md b/.changeset/gold-maps-promise.md new file mode 100644 index 000000000..c0c3ab237 --- /dev/null +++ b/.changeset/gold-maps-promise.md @@ -0,0 +1,5 @@ +--- +"emdash": patch +--- + +Add `fetchpriority="high"` to priority EmDash images so above-the-fold images can be requested eagerly and prioritized by the browser. diff --git a/docs/src/content/docs/guides/media-library.mdx b/docs/src/content/docs/guides/media-library.mdx index 3f6838182..4899f6e3b 100644 --- a/docs/src/content/docs/guides/media-library.mdx +++ b/docs/src/content/docs/guides/media-library.mdx @@ -230,11 +230,11 @@ const { entry: post } = await getEmDashEntry("posts", Astro.params.slug); ### Responsive Images -For responsive images, use Astro's Image component with external URLs: +For EmDash media fields, use the `Image` component from `emdash/ui`: ```astro --- -import { Image } from "astro:assets"; +import { Image } from "emdash/ui"; import { getEmDashEntry } from "emdash"; const { entry: post } = await getEmDashEntry("posts", Astro.params.slug); @@ -242,26 +242,15 @@ const { entry: post } = await getEmDashEntry("posts", Astro.params.slug); {post?.data.featured_image && ( {post.data.featured_image_alt )} ``` - +`priority` is for the primary above-the-fold image. It sets `loading="eager"` and `fetchpriority="high"`: `loading` controls whether loading is deferred, and `fetchpriority` gives the browser a priority hint for the request. ## Deleting Media diff --git a/docs/src/content/docs/themes/creating-themes.mdx b/docs/src/content/docs/themes/creating-themes.mdx index b2a2ecd5f..52b7aa408 100644 --- a/docs/src/content/docs/themes/creating-themes.mdx +++ b/docs/src/content/docs/themes/creating-themes.mdx @@ -294,6 +294,7 @@ const { post } = Astro.props; alt={post.data.featured_image.alt || post.data.title} width={800} height={450} + priority /> )}

{post.data.title}

@@ -306,6 +307,8 @@ const { post } = Astro.props; with `src` and `alt` -- writing `` renders `[object Object]`. +Use `priority` only for the likely above-the-fold image on a page, such as a hero or first card image. It renders the image with `loading="eager"` and `fetchpriority="high"`. `loading` controls whether the browser may defer loading, while `fetchpriority` hints how important the request is once the browser discovers it. + ## Using Menus Query admin-defined menus in your layouts. Never hard-code navigation links: diff --git a/packages/core/src/components/EmDashImage.astro b/packages/core/src/components/EmDashImage.astro index 710c58974..2d828053f 100644 --- a/packages/core/src/components/EmDashImage.astro +++ b/packages/core/src/components/EmDashImage.astro @@ -170,6 +170,7 @@ const imgProps: Record = { height: finalHeight, alt: finalAlt, loading: priority ? "eager" : "lazy", + fetchpriority: priority ? "high" : undefined, decoding: "async", style: placeholderStyle ? `${baseStyle} ${placeholderStyle}` : baseStyle, ...attrs,