Overview
At Zepto, delivering a fast and seamless user experience is paramount. For our e-commerce platform, especially on mobile devices, displaying a rich product catalog with many images can significantly impact page load times and overall performance. Implementing efficient image loading is crucial for a smooth user journey from browsing to checkout. This problem focuses on optimizing image delivery by implementing lazy loading.
What you need to do / Task
Your primary goal is to implement lazy loading for product images displayed in a scrollable list. You will be provided with a basic React component structure and mock product data. Your solution should ensure that images are only loaded when they are about to enter the user's viewport.
- Display Product Images: Render a list of product cards, each containing a product image and some basic details.
- Implement Lazy Loading: Utilize the
Intersection Observer API to defer loading of images that are not currently visible in the viewport.
- Show Placeholders: While an image is not yet loaded (either because it's out of view or still fetching), display a visual placeholder.
- Ensure Performance: The scrolling experience should remain smooth, even with many products.
UI/UX expectations
- Layout: Products should be displayed in a simple grid or list layout, allowing for vertical scrolling.
- Placeholders: Before an image loads, a distinct placeholder (e.g., a grey box, a subtle animation) should be visible in its place.
- Loading Behavior: Images should seamlessly replace their placeholders as they scroll into view and finish loading. There should be no abrupt content shifts (layout shifts) as images load.
- Responsiveness: The layout should be reasonably responsive, adapting to different screen widths (handled by provided CSS).
Acceptance criteria
- Initial Load: Only images that are initially within or very close to the user's viewport are loaded. Images further down the list should display placeholders.
- Scrolling Down: As the user scrolls down, images should begin loading just before or as they enter the viewport, replacing their placeholders.
- Scrolling Up: Images that have already been loaded should remain visible if the user scrolls back up.
- Smooth Interaction: Scrolling through the product list should be fluid and free of noticeable jank or stuttering.
- Placeholder Visibility: A placeholder is clearly visible for all images that are not yet loaded.