Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-maps-promise.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 5 additions & 16 deletions docs/src/content/docs/guides/media-library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -230,38 +230,27 @@ 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);
---

{post?.data.featured_image && (
<Image
src={post.data.featured_image}
alt={post.data.featured_image_alt ?? ""}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mvvmm Should we be concerned about dropping this line?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think these just override the images existing alt/src. My agent had an issue with implying they should be routinely overridden here, but I can add them back if you prefer.

image={post.data.featured_image}
width={800}
height={450}
priority
/>
)}
```

<Aside type="tip">
Configure allowed image domains in `astro.config.mjs` to use the Image component with external URLs:

```js title="astro.config.mjs"
export default defineConfig({
image: {
domains: ["media.example.com"],
},
});
```

</Aside>
`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

Expand Down
3 changes: 3 additions & 0 deletions docs/src/content/docs/themes/creating-themes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ const { post } = Astro.props;
alt={post.data.featured_image.alt || post.data.title}
width={800}
height={450}
priority
/>
)}
<h2><a href={`/posts/${post.slug}`}>{post.data.title}</a></h2>
Expand All @@ -306,6 +307,8 @@ const { post } = Astro.props;
with `src` and `alt` -- writing `<img src={post.data.featured_image} />` renders `[object Object]`.
</Aside>

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:
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/EmDashImage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const imgProps: Record<string, unknown> = {
height: finalHeight,
alt: finalAlt,
loading: priority ? "eager" : "lazy",
fetchpriority: priority ? "high" : undefined,
decoding: "async",
style: placeholderStyle ? `${baseStyle} ${placeholderStyle}` : baseStyle,
...attrs,
Expand Down
Loading