-
Notifications
You must be signed in to change notification settings - Fork 23.2k
Add loading attribute for audio and video #43434
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
+163
−19
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c719dac
Add loading attribute for audio and video
tunetheweb fef5851
Fix flaws
tunetheweb 4881ac1
Merge branch 'main' into lazy-load-media-content
tunetheweb 8e102dc
Update files/en-us/learn_web_development/extensions/performance/html/…
tunetheweb 6621187
Update files/en-us/web/api/htmlmediaelement/loading/index.md
tunetheweb 42a35ec
Review feedback
tunetheweb d228dc5
Merge branch 'main' into lazy-load-media-content
tunetheweb 05339da
More review feedback
tunetheweb 0f4cf99
Merge branch 'lazy-load-media-content' of github.com:tunetheweb/conte…
tunetheweb 5c97ed4
Apply suggestions from code review
tunetheweb 4added1
Merge branch 'lazy-load-media-content' of github.com:tunetheweb/conte…
tunetheweb 1582019
Formatting
tunetheweb ea78de6
Apply suggestions from code review
tunetheweb ba8b389
Update files/en-us/web/api/htmlmediaelement/loading/index.md
tunetheweb 055bb22
Update files/en-us/web/performance/guides/lazy_loading/index.md
tunetheweb bd994b7
Merge branch 'main' into lazy-load-media-content
tunetheweb 2209714
Merge branch 'main' into lazy-load-media-content
tunetheweb d4b2f0e
Update files/en-us/web/performance/guides/lazy_loading/index.md
tunetheweb a518968
Merge branch 'main' into lazy-load-media-content
tunetheweb 2f4cd62
Merge branch 'main' into lazy-load-media-content
tunetheweb 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
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
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
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
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
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
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
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
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
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,62 @@ | ||
| --- | ||
| title: "HTMLMediaElement: loading property" | ||
| short-title: loading | ||
| slug: Web/API/HTMLMediaElement/loading | ||
| page-type: web-api-instance-property | ||
| browser-compat: api.HTMLMediaElement.loading | ||
| --- | ||
|
|
||
| {{APIRef("HTML DOM")}} | ||
|
|
||
| The **`loading`** property of the {{domxref("HTMLMediaElement")}} interface provides a hint to the browser on how to handle the loading of the media which is currently outside the window's {{Glossary("visual viewport")}}. This helps to optimize the loading of the document's contents by postponing loading the media until it's expected to be needed, rather than immediately during the initial page load. It reflects the `<audio>` element's [`loading`](/en-US/docs/Web/HTML/Reference/Elements/audio#loading) content attribute or the `<video>` element's [`loading`](/en-US/docs/Web/HTML/Reference/Elements/video#loading) content attribute. | ||
|
|
||
| ## Value | ||
|
|
||
| A string whose value is one of `eager` or `lazy`. For their meanings, see the HTML [`<audio loading>`](/en-US/docs/Web/HTML/Reference/Elements/audio#loading) or [`<video loading>`](/en-US/docs/Web/HTML/Reference/Elements/video#loading) reference. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic usage | ||
|
|
||
| The `addVideoToList()` function shown below adds a video thumbnail to a list of items, using lazy-loading to avoid loading the video from the network until it's actually needed. | ||
|
|
||
| ```js | ||
| function addVideoToList(url) { | ||
|
tunetheweb marked this conversation as resolved.
|
||
| const list = document.querySelector("div.video-list"); | ||
|
|
||
| const newItem = document.createElement("div"); | ||
| newItem.className = "video-item"; | ||
|
|
||
| const newVideo = document.createElement("video"); | ||
|
|
||
| // Lazy-load if supported | ||
| if ("loading" in HTMLVideoElement.prototype) { | ||
| newVideo.loading = "lazy"; | ||
| } else { | ||
| // If native lazy-loading is not supported you may want to consider | ||
| // alternatives, though this may be fine as a progressive enhancement. | ||
| } | ||
|
|
||
| newVideo.width = 320; | ||
| newVideo.height = 240; | ||
| newVideo.src = url; | ||
|
|
||
| newItem.appendChild(newVideo); | ||
| list.appendChild(newItem); | ||
| } | ||
| ``` | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - The {{HTMLElement("audio")}} element | ||
| - The {{HTMLElement("video")}} element | ||
| - [Web performance](/en-US/docs/Learn_web_development/Extensions/Performance) in the MDN Learning Area | ||
| - [Lazy loading](/en-US/docs/Web/Performance/Guides/Lazy_loading) in the MDN web performance guide | ||
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
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
Oops, something went wrong.
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.