Frontend School

Lazy Load Image Gallery

Machine Coding
easy

Lazy Load Image Gallery

Easy
Frontend
React
JavaScript
Lazy Loading
Performance
UI

Overview

In modern web applications, especially those that are image-heavy like social media feeds or e-commerce product listings, loading all images upfront can severely impact initial page load time and user experience. Lazy loading is a crucial technique that defers the loading of off-screen images until the user scrolls them into the viewport, significantly improving performance and resource utilization. This problem challenges you to implement a basic image gallery with lazy loading.

What you need to do / Task

Your primary task is to build a React component that displays a collection of images. All images should be lazy-loaded, meaning their actual content (the src attribute) should only be fetched and rendered when they are about to become visible in the user's viewport.

  1. Render a grid of images using the provided mock data.
  2. Implement lazy loading for all images in the gallery.
  3. Ensure a visual placeholder is shown for images that are not yet loaded.

UI/UX expectations

  • The application should display a scrollable grid layout of image cards.
  • Each image card should contain an image and a title/description.
  • Images should only load their actual content when they are about to enter or are within the user's viewport.
  • Before an image loads, a simple placeholder (e.g., a gray box) should be visible in its place.
  • The gallery should be responsive and provide a smooth scrolling experience.

Acceptance criteria

  • Images are not loaded until they are scrolled into view (verifyable via network tab).
  • A visible placeholder is displayed for images before their actual content loads.
  • The application remains responsive during scrolling and image loading.
  • All images eventually load correctly when scrolled into view.
  • The gallery displays all provided mock images.

Constraints

Constraints & assumptions

  • You are provided with mock image data within the App.tsx file.
  • Focus on modern browser features where possible for implementing lazy loading.
  • No external libraries beyond React itself are needed for the core functionality.
  • The provided CSS serves as a starting point; feel free to modify or extend it as needed.

Out of scope

  • Advanced image optimization techniques (e.g., responsive images with srcset, different image formats like WebP).
  • Implementing an infinite scroll or pagination mechanism (all mock images are available initially).
  • Complex error handling for image loading.
  • Browser compatibility for very old browsers.

What interviewers evaluate

  • Correctly implements lazy loading for images using an appropriate and performant technique.
  • Demonstrates understanding of performance implications in UI rendering.
  • Produces clean, readable, and well-structured React code.
  • Ensures a good user experience by providing visual feedback (placeholders) during loading.

Loading editor...