3.17 Manage Dependencies Appropriately
While JavaScript may not cause the most website bloat, it can cause very high emissions in terms of CPU load due to the rendering process, thereby it makes sense to consider the use of dependencies and third-party code carefully.
Criteria
- Dependency Management: Prevent developers from downloading and installing JavaScript libraries to run locally (client-side) when they are not needed by checking for unused dependencies and uninstalling those that aren’t needed and removing them from your package.json file.
- Dependency Necessity: Only use libraries where necessary as this will reduce the amount of JavaScript that has to be downloaded and parsed by the browser. Consider whether you can use a native JavaScript API instead. Check the package size, and whether individual modules can be installed and imported rather than the whole library.
- Dependency Updates: Regularly check dependencies and keep them up-to-date.
Impact
Medium
Effort
Low
Benefits
- Environmental:
Developer’s machines do not need to waste energy installing and / or rendering packages that are not needed. - Security:
Third-party code can contain bugs and security issues. Keeping packages up-to-date and using fewer third-party libraries reduces the likelihood of security flaws. - Performance:
Reduction in client-side JavaScript normally results in faster websites.
GRI
- materials: Low
- energy: Low
- water: Low
- emissions: Low
Example
- Code:
npm uninstall lodash
- Uninstalling packages and dependencies.
Resources
- Bundlephobia
- Equations relating total annual energy consumption and chips energy efficiency
- [GPFEDS] 2.9 – Specifications (Off-The-Shelf Components) (PDF)
- [GPFEDS] 2.10 – Specifications (Third-Party Services) (PDF)
- [GPFEDS] 3.1 – Architecture (Impact Reduction) (PDF)
- [GR491] 2-7025 – Reducing Dependencies
- [GR491] 3-5020 – Unused Dependencies
- How to Check if You Have Unused Dependencies in Your JavaScript App
- How to Keep Your App Dependencies Up-To-Date?
- Keeping dependencies up-to-date
- Pkg-Size
- Should Developers Use Third-Party Libraries?
- Uninstalling packages and dependencies
- United Nations [SDGS] Goal 12 (Consumption & Production)
- Up To Date