You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: eslint-plugin/docs/rules/prefer-lighter-formats-for-image-files.md
+17-29Lines changed: 17 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,17 @@ Some image formats are generally considered better for eco-friendly web design a
12
12
13
13
We recommend using the following formats:
14
14
15
-
-*WebP*, developed by Google, is a modern image format that provides high compression efficiency without significant loss of quality.
16
-
-*AVIF* (AV1 Image File Format) is a relatively new and highly efficient image format that is based on the AV1 video codec.
17
-
-*SVG* (Scalable Vector Graphics) is a vector image format that is based on XML.
18
-
Files are lightweight and can be scaled without loss of quality.
15
+
-**WebP**, developed by Google, is a modern image format that provides high compression efficiency without significant loss of quality.
16
+
-**AVIF** (AV1 Image File Format) is a relatively new and highly efficient image format that is based on the AV1 video codec.
17
+
-**SVG** (Scalable Vector Graphics) is a vector image format that is based on XML.
18
+
Files are lightweight and can be scaled without loss of quality.
19
19
20
20
```html
21
-
<imgsrc="./assets/images/cat.jpg"alt="Unoptimized image of a cat"/> // Non-compliant
21
+
<imgsrc="./assets/images/cat.jpg"alt="Unoptimized image of a cat" /> //
22
+
Non-compliant
22
23
23
-
<imgsrc="./assets/images/cat.webp"alt="Optimized image of a cat"/> // Compliant
24
+
<imgsrc="./assets/images/cat.webp"alt="Optimized image of a cat" /> //
25
+
Compliant
24
26
```
25
27
26
28
Remember that the best image format may vary depending on the specific use case, content, and requirements of your website.
@@ -43,7 +45,7 @@ Format importantly impacts images size: on average, .webp images will be 30% lig
43
45
images or .png images. .avif images can be up to 20% lighter than .webp image and 50% lighter than .jepg images.
44
46
45
47
Don't forget to pay attention to browser support. .webp images will not be recognized by
46
-
old browsers and will not be displayed. It is possible to provide several formats for the same image
48
+
old browsers and will not be displayed. It is possible to provide several formats for the same image
47
49
to overcome this issue. Some server-side modules (such as Google's modPageSpeed, also available for Apache
48
50
and Nginx) even allow you to provide the appropriate image for the browser that is calling the server.
49
51
@@ -58,13 +60,13 @@ Many tools will help you minimize images size:
58
60
### Example
59
61
60
62
In this example, the DOM <picture> element informs the browser that there are two images: a .webp image and a
61
-
.jpg image, which is used by default. The browser will decide which image will be downloaded. If the .webp format
63
+
.jpg image, which is used by default. The browser will decide which image will be downloaded. If the .webp format
62
64
is supported, the image.webp image will be downloaded; otherwise, image.jpg image will be downloaded.
63
65
64
66
```html
65
67
<picture>
66
-
<sourcesrcset="image.webp"type="image/webp">
67
-
<imgsrc="image.jpg"alt="..."loading="lazy">
68
+
<sourcesrcset="image.webp"type="image/webp" />
69
+
<imgsrc="image.jpg"alt="..."loading="lazy" />
68
70
</picture>
69
71
```
70
72
@@ -76,25 +78,11 @@ To address this issue, you can supply multiple formats for the same image.
76
78
77
79
### Documentation
78
80
79
-
-https://github.com/cnumr/best-practices/blob/main/chapters/BP_080_en.md[CNUMR best practices] - Optimize images
81
+
-[CNUMR best practices](https://github.com/cnumr/best-practices/blob/main/chapters/BP_080_en.md) - Optimize images
82
+
-[WSG UX15-2](https://w3c.github.io/sustyweb/star.html#UX15-2) - Optimizing All Image Assets for a Variety of Different Resolutions
83
+
-[RGESN 5.1](https://ecoresponsable.numerique.gouv.fr/publications/referentiel-general-ecoconception/critere/5.1/) - Référentiel général d'écoconception de services numériques 🇫🇷
80
84
81
85
### Articles & blog posts
82
86
83
-
-https://greenspector.com/en/which-image-format-to-choose-to-reduce-its-energy-consumption-and-its-environmental-impact/[greenspector.com - Which image format choose to reduce energy consumption and environmental impact?]
84
-
-https://dodonut.com/blog/use-cases-of-web-image-formats/[dodonut.com - The Most Efficient Web Image Formats. Use Cases For Different Types Of Images.]
85
-
86
-
### WSG
87
-
-[UX15-2: Optimizing All Image Assets for a Variety of Different Resolutions](https://w3c.github.io/sustyweb/star.html#UX15-2)
Choose the image format best suited to the type of image and display context: use vector formats such as svg whenever possible (illustrations, icons, logos, graphs, etc.), jpg for photos and png for illustrations with solid colors.
98
-
99
-
#### Means of test or control
100
-
Evaluate the relevance of the image format displayed.
87
+
-[greenspector.com - Which image format choose to reduce energy consumption and environmental impact?](https://greenspector.com/en/which-image-format-to-choose-to-reduce-its-energy-consumption-and-its-environmental-impact/)
88
+
-[dodonut.com - The Most Efficient Web Image Formats. Use Cases For Different Types Of Images.](https://dodonut.com/blog/use-cases-of-web-image-formats/)
0 commit comments