Overview
Myntra's product catalog pages often display a large number of items, each with one or more images. Loading all these images upfront can significantly degrade page load performance and user experience, especially on slower networks or devices. To combat this, implementing an efficient lazy loading mechanism for product images is crucial. This ensures that images are only fetched and rendered when they are about to become visible in the user's viewport, optimizing resource utilization and perceived performance.
What you need to do / Task
Your task is to build a React application that displays a list of product cards. Each product card will feature an image and some basic product information. The core requirement is to implement lazy loading for all product images.
- Display Product List: Render a scrollable list of product cards using the provided mock data.
- Implement Lazy Loading: Utilize the native
Intersection Observer API to detect when a product image enters the viewport.
- Load Images On Demand: When an image is observed to be intersecting the viewport, load its high-resolution
src attribute.
- Placeholder Display: Before an image is loaded, display a visible placeholder (e.g., a solid color block, a low-res preview, or a simple spinner) within the image area.
- Prevent Reloads: Ensure that once an image has been loaded, it does not attempt to reload on subsequent scrolls or re-intersections.
UI/UX expectations
- The application should present a vertically scrollable grid or list of product cards.
- Each product card should have a clearly defined area for the image at the top, followed by product name and brand.
- The placeholder should be distinctly visible before the actual image appears.
- Image loading should be smooth, without noticeable jank or significant layout shifts as images appear.
- The overall layout should be responsive enough to adapt to different screen widths (e.g., using CSS Grid).
Acceptance criteria
- On initial page load, images outside the visible viewport display their respective placeholders.
- As the user scrolls down, images entering the viewport transition from placeholder to their actual high-resolution content.
- Images that have already been loaded remain visible and do not attempt to reload when scrolled out of and back into view.
- A visual placeholder is consistently shown for images that are not yet loaded.
- The application remains performant during scrolling and image loading, with no noticeable UI freezes or excessive network requests.