Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.97 KB

avoid-autoplay.md

File metadata and controls

44 lines (32 loc) · 1.97 KB

Avoid autoplay for videos and audio content (@creedengo/avoid-autoplay)

⚠️ This rule warns in the ✅ recommended config.

Why is this an issue?

Automatic videos and audio files activation (autoplay) during web pages loading uses resources on each tier (device, network, data center). In many cases, automatic playback is not necessary. Moreover, it can draw users' attention and distract them from the initially requested service. Therefore, whenever possible, these playbacks should be initiated by the users and by not using the autoplay attributes in the <audio> and <video> elements.

Nevertheless, some parts of the video or audio files may be downloaded even if autoplay is not activated. Moreover, data will be unnecessarily downloaded even if users do not start the video playback. It is therefore necessary to force browsers not to preload anything by setting the preload attribute to none.

return (
    <>
        <video src="video.mp4" autoplay/> // Non-compliant
        <video src="video.mp4" preload="auto"/> // Non-compliant
        <video src="video.mp4" autoplay preload="auto"/> // Non-compliant
        <video src="video.mp4" preload="none"/> // Compliant
    </>
)

This rule is build for React and JSX.

Resources

Documentation