Quick PSA for every developer, especially beginners:
The code we write runs on servers, and servers use electricity.
Data centers around the world consume a large amount of energy, and a lot of that still comes from fossil fuels. The good news is that small choices in our code can reduce waste.
5 Simple Habits for Greener Code
1. Optimize your images
Large images mean more data transfer and more energy. Compress images and use modern formats like WebP.
2. Don't load what you don't need
Remove unused libraries and scripts. A smaller website loads faster and uses less power.
3. Write efficient code
Avoid unnecessary loops and repeated API calls. For example:
// Wasteful: calling the API inside a loop
for (let i = 0; i < ids.length; i++) {
fetch(`/api/user/${ids[i]}`);
}
// Better: one request for all data
fetch(`/api/users?ids=${ids.join(",")}`);
4. Use caching
Don't fetch the same data again and again. Caching saves time, bandwidth, and energy.
5. Turn off what you aren't using
Shut down unused test servers, free-tier projects, and old cloud resources.
Why Does It Matter?
A single website may not seem like much, but millions of websites and apps running every day add up. Efficient code is good for your users, your wallet, and the planet.
Your Turn
What is one thing you do to make your code or your workflow more eco-friendly? Share it in the comments! 👇
Top comments (0)