Skip to content

Lazy Loading

Lazy Loading is a performance optimization technique that delays the loading of ad placements until they are about to become visible in the viewport. This improves page performance by reducing initial load time and bandwidth usage, while increasing viewability rates.

When a placement is configured with lazy loading enabled, Htag:

  1. Monitors the user’s scrolling behavior
  2. Calculates the distance between the placement and the viewport
  3. Loads the ad only when the placement is within a specified threshold of becoming visible

Lazy loading is configured at the placement level using the lazyloading parameter. This parameter can be set when defining a placement using the definePlacement method.

Lazy loading works seamlessly with the Htag events system. The events fire in a specific sequence that reflects the lazy loading process:

When lazy loading is disabled, events fire immediately:

element.exists → element.requestable → element.renderable

When lazy loading is enabled, there’s a delay before the ad request:

element.exists → [Wait for viewport proximity] -> element.requestable → [Wait for viewport proximity] → element.renderable