-
Notifications
You must be signed in to change notification settings - Fork 10k
[Images] Tutorial for lazy loading #23371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
19107a4
[Images] Tutorial for lazy loading
ToriLindsay ee88abe
language tweak
ToriLindsay bfee5d5
Update src/content/docs/images/tutorials/optimize-images-for-mobile.mdx
ToriLindsay d351a0e
Updates based on content feedback
ToriLindsay 4244158
Feedback - define lazy loading
ToriLindsay 2234fe9
Swapped around info based on feedback
ToriLindsay 538da9f
Update src/content/docs/images/tutorials/optimize-mobile-viewing.mdx
ToriLindsay fe869cc
Update src/content/docs/images/tutorials/optimize-mobile-viewing.mdx
ToriLindsay 7e6f14e
Update src/content/docs/images/tutorials/optimize-mobile-viewing.mdx
ToriLindsay f2a774d
Update src/content/docs/images/tutorials/optimize-mobile-viewing.mdx
ToriLindsay adf02fe
Update src/content/docs/images/tutorials/optimize-mobile-viewing.mdx
ToriLindsay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/content/docs/images/tutorials/optimize-images-for-mobile.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| pcx_content_type: tutorial | ||
| title: Optimize mobile viewing with lazy loading | ||
| 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. | ||
| sidebar: | ||
| order: 1 | ||
| --- | ||
|
|
||
| Lazy loading is an easy way to optimize the images on your webpages for mobile viewing. Lazy loading has two main advantages: | ||
| * **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. | ||
| * **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. | ||
|
|
||
| Lazy loading is natively supported on all Chromium-based browsers like Chrome, Safari, Firefox, Opera, and Edge. | ||
|
|
||
| :::note | ||
| 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. | ||
| ::: | ||
|
|
||
| ## How to add lazy loading to images | ||
ToriLindsay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To add lazy loading to your images, modify the `loading` attribute of your `<img>` tags to be `"lazy"`. For example: | ||
|
|
||
| ````HTML | ||
| <img src="example.com/cdn-cgi/width=300/image.png" loading="lazy"> | ||
| ```` | ||
|
|
||
| :::note[Exception for images in the viewport] | ||
| If you have images that are in the viewport, these will load faster with a `loading` attribute of `"eager"` instead of `"lazy"`. For example: | ||
| ````HTML | ||
| <img src="example.com/cdn-cgi/width=300/image.png" loading="lazy"> | ||
| ```` | ||
| ::: | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.