Skip to content

Commit d351a0e

Browse files
committed
Updates based on content feedback
1 parent bfee5d5 commit d351a0e

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

src/content/docs/images/tutorials/optimize-images-for-mobile.mdx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
pcx_content_type: tutorial
3+
title: Optimize mobile viewing
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. This helps address common challenges of mobile viewing, like slow network connections or weak processing capabilities.
10+
11+
Lazy loading has two main advantages:
12+
* **Faster page load times** — Images are loaded as the user scrolls down the page, instead of all at once when the page is opened.
13+
* **Lower costs for image delivery** — When using Cloudflare Images, you only pay to load images that the user actually sees. With lazy loading, images that are not scrolled into view do not count toward your billable Images requests.
14+
15+
Without lazy loading, for most browsers, all images are fetched by default, which takes longer. Images are prioritized based on their distance from the viewport, so images in or close to the viewport are loaded first.
16+
17+
Lazy loading is natively supported on all Chromium-based browsers like Chrome, Safari, Firefox, Opera, and Edge.
18+
19+
:::note
20+
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.
21+
:::
22+
23+
## Modify your loading attribute
24+
25+
There are two possible `loading` attributes for your `<img>` tags: `lazy` and `eager`.
26+
27+
### Lazy loading
28+
29+
Lazy loading is recommended for most images.
30+
31+
Example of modifying the `loading` attribute of your `<img>` tags to be `"lazy"`:
32+
````HTML
33+
<img src="example.com/cdn-cgi/width=300/image.png" loading="lazy">
34+
````
35+
36+
### Eager loading
37+
38+
If you have images that are in the viewport, eager loading, instead of lazy loading, is recommended.
39+
40+
Example of modifying the `loading` attribute of your `<img>` tags to be `"eager"`:
41+
````HTML
42+
<img src="example.com/cdn-cgi/width=300/image.png" loading="lazy">
43+
````

0 commit comments

Comments
 (0)