Skip to content

Commit 0669d28

Browse files
committed
perf: optimize image loading for first blog post card
Update the Card component to accept loading and fetchpriority props. Apply eager loading and high fetch priority to the first post in both Blog-grid and Blog-list sections to improve rendering performance. Signed-off-by: Lorenzo Croce <lorenzo.croce@arenastudios.it>
1 parent b483c7e commit 0669d28

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/components/Card/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Image from "../image";
66
import { CardWrapper } from "./Card.style";
77
import { useStyledDarkMode } from "../../theme/app/useStyledDarkMode";
88

9-
const Card = ({ frontmatter, fields }) => {
9+
const Card = ({ frontmatter, fields, loading = "lazy", fetchpriority = "auto" }) => {
1010

1111
const { isDark } = useStyledDarkMode();
1212

@@ -18,6 +18,8 @@ const Card = ({ frontmatter, fields }) => {
1818
{...((isDark && frontmatter.darkthumbnail && frontmatter.darkthumbnail.publicURL !== frontmatter.thumbnail.publicURL)
1919
? frontmatter.darkthumbnail : frontmatter.thumbnail)}
2020
imgStyle={{ objectFit: "contain" }}
21+
loading={loading}
22+
fetchpriority={fetchpriority}
2123
alt={frontmatter.title}
2224
/>
2325
</div>

src/sections/Blog/Blog-grid/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const BlogGrid = ({
6161
</Col>
6262
)}
6363

64-
{searchedPosts.length > 0 && searchedPosts.map(({ id, frontmatter, fields }) => (
64+
{searchedPosts.length > 0 && searchedPosts.map(({ id, frontmatter, fields }, index) => (
6565
<Col key={id} $xs={12} $sm={6}>
66-
<Card frontmatter={frontmatter} fields={fields} />
66+
<Card frontmatter={frontmatter} fields={fields} loading={index === 0 ? "eager" : "lazy"} fetchpriority={index === 0 ? "high" : "auto"} />
6767
</Col>
6868
))}
6969
<Col>

src/sections/Blog/Blog-list/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ const BlogList = ({
7474
}}
7575
className="blog-lists">
7676
{searchedPosts.length > 0 &&
77-
searchedPosts?.map(({ id, frontmatter, fields }) => (
77+
searchedPosts?.map(({ id, frontmatter, fields }, index) => (
7878
<Col $xs={12} key={id}>
79-
<Card frontmatter={frontmatter} fields={fields} />
79+
<Card frontmatter={frontmatter} fields={fields} loading={index === 0 ? "eager" : "lazy"} fetchpriority={index === 0 ? "high" : "auto"} />
8080
</Col>
8181
))}
8282
<Col>

0 commit comments

Comments
 (0)