practiceEngineering & architecture

Lazy Loading

Lazy loading defers a non-critical resource or feature until it is likely to be needed instead of loading it during the initial experience.

Download Markdown (.md)

01What it means

Lazy loading is a delivery strategy that postpones fetching, decoding, initializing, or rendering work until a later signal such as proximity to the viewport, navigation, or explicit interaction. It can apply to images, frames, code, data, or components. Code splitting creates loadable boundaries; lazy loading decides when to use them.[1][2]

Work deferred until a useful signal Delay noncritical resources without creating a later interaction stall
  1. 01Classify resourceNeeded for initial task or later
  2. 02Create boundaryImage, frame, code, data, component
  3. 03Watch signalViewport proximity, navigation, interaction
  4. 04Load with fallbackReserve space, error, no-script behavior
  5. 05Measure tradeoffInitial savings, later latency, stability, failures

Code splitting creates a loadable boundary; lazy loading decides when to fetch, decode, initialize, or render it.

02Why it matters

Deferring unnecessary work can improve startup speed, data use, memory, and main-thread availability. Deferring the wrong work merely moves latency into a critical interaction and can cause layout shifts or missing content.

03When to use it

Use it for below-the-fold media, uncommon routes, heavy optional tools, or secondary data with a reliable trigger. Load essential content and controls eagerly, and reserve dimensions and meaningful fallbacks for deferred elements.

04How it works

  1. Classify resources by whether the initial task truly requires them.
  2. Choose a browser feature or application signal that predicts need.
  3. Reserve space and provide loading, error, and no-script behavior where necessary.
  4. Start work early enough to avoid a user-visible stall but not on every visit.
  5. Measure initial savings, later interaction latency, layout stability, and failure rates.

05A practical example

Example

An editorial page loads its lead image normally but marks distant article images for browser lazy loading with dimensions. Readers transfer less data, and reserved space prevents the article from jumping as images arrive.

06Where it breaks

Prediction can be wrong, deferred requests can compete with later critical work, and unsupported or script-dependent strategies need fallbacks. Lazy loading does not reduce the cost for users who eventually load everything.

Common mistakes

  • Lazy-loading the primary image or content needed for the first view.
  • Omitting image dimensions and causing layout shifts.
  • Triggering loads only after a user reaches an empty placeholder.
  • Using scroll listeners when a native attribute or observer is more reliable.

07Sources

  1. Lazy loadingMDN Web Docs · Official technical documentationLazy loading
  2. HTML Standard: Lazy Loading AttributesWHATWG · Living web standardHTML Standard: Lazy Loading Attributes
View saved topics

Start typing to search titles, definitions, categories, and frameworks.