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): Add lazy loading for images #784

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

senthil-athiban
Copy link

@senthil-athiban senthil-athiban commented Jun 13, 2024

PR Fixes:

This PR introduces LazyLoadImage, a library that enables lazy loading of images using react-lazy-load-image-component. Aims to improves performance by delaying image loading until they're needed, reducing initial page load times and conserving bandwidth

Resolves #783

Checklist before requesting a review

  • I have performed a self-review of my code
  • I assure there is no similar/duplicate pull request regarding same issue

@siinghd
Copy link
Collaborator

siinghd commented Jun 13, 2024

@senthil-k8s i would not use this ,please try to create a custom lazy load component with Image(component) of nextjs.

it can be a simple component with a state like:

const [loading,setLoading] = useState(true);
<Image
...
onLoad={(e) => setLoading(false)} 
/>

Just search little bit online for optimizations etc

@senthil-athiban
Copy link
Author

senthil-athiban commented Jun 14, 2024

@siinghd Using the Image component of Next.js requires width and height, in the existing img tag in our codebase, I couldn't find the specified width and height. Shall I use the Image component of Next.js or the default img tag?

Demo: https://www.loom.com/share/d622a54442214bd3b6e33bacdb43a4a6

@siinghd
Copy link
Collaborator

siinghd commented Jun 14, 2024

@senthil-k8s Use nextjs and provide width and height suitable

@senthil-athiban
Copy link
Author

@siinghd Done!

import Image from 'next/image';
import React, { useState, useRef, useEffect } from 'react';

const registerObserver = (
Copy link
Collaborator

@siinghd siinghd Jun 19, 2024

Choose a reason for hiding this comment

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

what is this complex logic? NextJs Image its already loas images like that...
what i was saying is until the image isnt loaded show the skeleton

Copy link
Author

@senthil-athiban senthil-athiban Jun 20, 2024

Choose a reason for hiding this comment

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

This is to observe the viewport by writing custom logic. Utilizing this LazyLoadImage component, we can customize our own skeleton, and styling effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: Add Lazy Loading with Blur Effect to Images
2 participants