Skip to content
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

Add HTML rule "Avoid autoplay for videos and audio content" #298

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#298](https://github.com/green-code-initiative/ecoCode/pull/298) Add HTML rule EC36 (Avoid autoplay for videos and audio content)

### Changed

### Deleted
Expand Down
107 changes: 54 additions & 53 deletions RULES.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions ecocode-rules-specifications/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@
</descriptors>
</configuration>
</execution>
<execution>
<id>assembly-html</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/html.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
Expand Down
18 changes: 18 additions & 0 deletions ecocode-rules-specifications/src/main/assembly/html.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.1 https://maven.apache.org/xsd/assembly-2.1.1.xsd">
<id>html</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<includes>
<include>io/ecocode/rules/html/*.*</include>
</includes>
<outputDirectory/>
</fileSet>
</fileSets>
</assembly>
22 changes: 22 additions & 0 deletions ecocode-rules-specifications/src/main/rules/EC36/EC36.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"title": "Avoid autoplay for videos and audio content",
"type": "CODE_SMELL",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "EFFICIENT"
},
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"ecocode",
"eco-design",
"video",
"audio"
],
"defaultSeverity": "Major"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
:!sectids:

== Why is this an issue?

Autoplaying media consumes unnecessary energy, especially when users might not be actively engaging with the content.
This can drain battery life on devices, particularly on mobile devices, leading to increased energy consumption and potentially contributing to environmental impact.
It can also consume data, particularly for users on limited data plans or in areas with poor internet connectivity.
This can lead to unnecessary data usage and potentially increased costs for users.

However, even without autoplay, segments of video or audio files might still download.
This leads to unnecessary data usage, especially if users don't commence playback.
To mitigate this, it's crucial to prevent browsers from preloading any content by configuring the appropriate settings.

Video:

[source,html,data-diff-id="1",data-diff-type="noncompliant"]
----
<video src="videofile.webm" autoplay></video> // Non-compliant
----

[source,html,data-diff-id="1",data-diff-type="compliant"]
----
<video src="videofile.webm" preload="none"></video> // Compliant
----

Audio:

[source,html,data-diff-id="1",data-diff-type="noncompliant"]
----
<audio controls src="audiofile.mp3" autoplay></audio> // Non-compliant
----

[source,html,data-diff-id="1",data-diff-type="compliant"]
----
<audio controls src="audiofile.mp3" preload="none"></audio> // Compliant
----

== Resources

=== Documentation

- https://github.com/cnumr/best-practices/blob/main/chapters/BP_4003_en.md[CNUMR best practices] - Avoid autoplay for videos and audio content

=== Articles & blog posts

- https://eco-conception.designersethiques.org/guide/en/content/5-2-video.html[eco-conception.designersethiques.org - 5.2. Video and sound]
- https://www.ecoindex.fr/en/ecodesign/[www.ecoindex.fr - Some good practices]
Loading