Skip to content

Commit f7b060e

Browse files
authored
feat: optimize blog image loading wit priority, lazy and quality (#1703)
Signed-off-by: karan-palan <[email protected]>
1 parent 0eb78c7 commit f7b060e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

pages/blog/index.page.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ export default function StaticMarkdownPage({
204204
width={800}
205205
height={450}
206206
className='object-cover w-full h-full opacity-70 blur-[5px]'
207-
alt='hero image example'
207+
alt={recentBlog[0].frontmatter.title}
208+
priority
209+
quality={75}
208210
/>
209211
<div className='absolute text-white w-full h-full mt-custom ml-14'>
210212
{/* Display all categories (joined by comma) */}
@@ -298,7 +300,7 @@ export default function StaticMarkdownPage({
298300

299301
{/* Blog Posts Grid */}
300302
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 xl:grid-cols-5 gap-6 grid-flow-row mb-20 bg-white dark:bg-slate-800 mx-auto p-4'>
301-
{sortedFilteredPosts.map((blogPost: any) => {
303+
{sortedFilteredPosts.map((blogPost: any, idx: number) => {
302304
const { frontmatter, content } = blogPost;
303305
const date = new Date(frontmatter.date);
304306
const postTimeToRead = Math.ceil(readingTime(content).minutes);
@@ -310,12 +312,15 @@ export default function StaticMarkdownPage({
310312
href={`/blog/posts/${blogPost.slug}`}
311313
className='inline-flex flex-col flex-1 w-full'
312314
>
313-
<div className='h-max-[200px] w-full object-cover'>
314-
<div
315-
className='bg-slate-50 h-[160px] w-full self-stretch mr-3 bg-cover bg-center'
316-
style={{
317-
backgroundImage: `url(${frontmatter.cover})`,
318-
}}
315+
<div className='relative h-[160px] w-full'>
316+
<Image
317+
src={frontmatter.cover}
318+
alt={frontmatter.title}
319+
fill
320+
className='object-cover'
321+
loading={idx < 10 ? 'eager' : 'lazy'}
322+
priority={idx < 10}
323+
quality={75}
319324
/>
320325
</div>
321326
<div className='p-4 flex flex-col flex-1 justify-between'>

0 commit comments

Comments
 (0)