Lazy Loading

Lazy loading

As defined by MDNarrow-up-right

Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the length of the critical rendering patharrow-up-right, which translates into reduced page load times.

So, by applying lazy-loading strategies your page will load much faster as the assets will be loaded only when they're really needed (when they first appear in the viewable area for the user).

A good example of this are images: you won't probably need to load all the images in your page as you only need those images that appear in the viewable area for the user on first load. A better strategy is to load only the images that are in the viewable area for the user, and then load those images as they enter into this viewable area (if the user do not scroll, those images will never be loaded).

The same strategy can be applied to iframes and other resources that require a request to the server.

How to apply lazy-loading in Frontity projects

Frontity provides the <Image />arrow-up-right and <Iframe />arrow-up-right React components that adds lazy-loading to them. They're available through the @frontity/componentsarrow-up-right package.

The <Link>arrow-up-right component provides a sort-of lazy-loading behaviour called link prefechingarrow-up-right.

Finally, with the Intersection Observer Hooksarrow-up-right provided by the @frontity/hooksarrow-up-right package you can create your custom logic to be triggered only when the React element reaches the viewable area.

Last updated

Was this helpful?