Skip to content

Commit 19107a4

Browse files
committed
[Images] Tutorial for lazy loading
1 parent 3b23c47 commit 19107a4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
pcx_content_type: tutorial
3+
title: Optimize mobile viewing with lazy loading
4+
description: Lazy loading is an easy way to optimize the images on your webpages for mobile devices, with faster page load times and lower costs.
5+
sidebar:
6+
order: 1
7+
---
8+
9+
Lazy loading is an easy way to optimize the images on your webpages for mobile viewing. Lazy loading has two main advantages:
10+
* **Faster page load times** — Images are loaded as the user scrolls down the page, instead of all at once when the page is opened. This means faster page load times, especially for mobile users who may experience slow network connections or weak processing capabilities.
11+
* **Lower costs for image delivery** — You only pay to load images that the user actually sees. If an image is not scrolled into view by the user, it is not loaded, so it will not count toward your billable requests.
12+
13+
Lazy loading is natively supported on all Chromium-based browsers like Chrome, Safari, Firefox, Opera, and Edge.
14+
15+
:::note
16+
If you use older methods, involving custom Javascript or a Javascript library, lazy loading may increase the initial load time of the page since the browser needs to download, parse, and execute Javascript.
17+
:::
18+
19+
## How to set up lazy loading
20+
21+
To set up lazy loading, modify the `loading` attribute of your `<img>` tags to be `"lazy"`. For example:
22+
23+
````HTML
24+
<img src="example.com/cdn-cgi/width=300/image.png" loading="lazy">
25+
````
26+
27+
:::note[Exception for images in the viewport]
28+
If you have images that are in the viewport, these will load faster with a `loading` attribute of `"eager"` instead of `"lazy"`. For example:
29+
````HTML
30+
<img src="example.com/cdn-cgi/width=300/image.png" loading="lazy">
31+
````
32+
:::

0 commit comments

Comments
 (0)