Skip to content

Commit 4c8c329

Browse files
author
vluce
committed
GCI1234 Optimize browserlist tag in package.json #Javascript #RulesSpecifications #TERRE
1 parent 458ab17 commit 4c8c329

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

RULES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Some are applicable for different technologies.
8383
| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚀 |
8484
| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 |
8585
| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | 🚫 | 🚫 |
86+
| GCI1234 | Optimize browserlist tag in package.json | Determine the target browsers for yor application and configure the browserlists in package.json accordingly. | | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 |
8687

8788
## Rules to be reworked / measured / clarified
8889

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"title": "Browserlist Tag Optimization",
3+
"type": "CODE_SMELL",
4+
"status": "ready",
5+
"remediation": {
6+
"func": "Constant/Issue",
7+
"constantCost": "5min"
8+
},
9+
"tags": [
10+
"sobriety",
11+
"creedengo",
12+
"environment",
13+
"eco-design"
14+
],
15+
"defaultSeverity": "Info"
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
:!sectids:
2+
3+
== Why is this an issue?
4+
5+
When using webpack the bundle is configured with the browserfile tag in the package.json file.
6+
Optimize the browserfile to only target the browser you want to serve and avoid some polyfill script which can unnecessarily make your package bigger.
7+
8+
2 configurations can be distinguished :
9+
* Intranet : You know which browser are used in your company. So you can reduce the list of allowed browsers. For example, you can just allow edge and chrome, your bundle (build package) will be smaller.
10+
* Internet : You should allow a maximum of browsers, your bundle will include polyfill scripts and be bigger but will serve the most part of browsers types.
11+
12+
https://browsersl.ist/
13+
14+
[source,typescriptjsx,data-diff-id="1",data-diff-type="noncompliant"]
15+
----
16+
```json
17+
"browserslist": {
18+
"defaults"
19+
}
20+
```
21+
----
22+
23+
[source,typescriptjsx,data-diff-id="1",data-diff-type="compliant"]
24+
----
25+
```json
26+
"browserslist": {
27+
"production": [
28+
">0.2%",
29+
"not dead",
30+
"not op_mini all"
31+
],
32+
}
33+
```
34+
----
35+
36+
37+
== Resources
38+
39+
=== Documentation
40+
41+
42+
=== Articles & blog posts

0 commit comments

Comments
 (0)