How to prevent html5 video from loading before playing?
HtmlVideoHtml5 VideoHtml Problem Overview
I have several html5 videos on one page and I've just realized that when you visit the page, all the videos start loading even though I haven't clicked play on any of them.
Is there a way to only load a video once you click play, to prevent unnecessary downloading?
Html Solutions
Solution 1 - Html
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls="controls" preload="none">
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
</body>
</html>
Use Preload"none"
Solution 2 - Html
You should use the preload
attribute, and set its value to none
.
Quote from the <video>
specification
>preload
= "none" or "metadata" or "auto" or "" (empty string) or empty
Represents a hint to the UA about whether optimistic downloading of the video itself or its metadata is considered worthwhile.
- "none": Hints to the UA that the user is not expected to need the video, or that minimizing unnecessary traffic is desirable.
Solution 3 - Html
Just use <video preload="none">
And if you want to load meta data only of video then use <video preload="metadata">