Green Code: Reducing your websites' carbon footprint
Quantifying and reducing your web application's carbon emissions

Gurgaon, India
Search for a command to run...
Quantifying and reducing your web application's carbon emissions

Gurgaon, India
Ni
Thanks for this insightful article! As a developer, I don't often associate or think about my carbon footprint when building apps so I learned a lot from this article 😊
I'm not sure how much this matters in the era where generative AI writes code for you. However, still I embark upon this journey hoping this will help someone write better react code. Why you should organize your react components React itselft is uno...
Ultimate CDK deployment guide for Fargate. It works for any nodeJS Container too.

WARNING: Highly opinionated views against ionic and angular, opinions are mostly out of personal experience
Easy releasing beta versions of new features with your create-react-app based single page application just by changing the deployment directory
This is a post inspired from one of the React India '22 Topics.
Everyone thought going digital was better for the environment, but nobody considered the ecological impact of large data centres and edge locations, their emissions and generated heat.
Now is the time when we should start improving it. But improving something that we cannot measure is difficult. However few organisations have now come up with a fairly acceptable way to measuring the carbon impact.
tl;dr lot of mathematics
According to this source (link)
Therefore, we can assume Annual Internet Energy / Annual End User Traffic = 0.81 tWh/EB or 0.81 kWh/GB
Energy consumed for first time visitors = Data transfer for first time visitors (GB) x 0.81kWh/GB x 0.75
Energy consumed for returning visitors = Data transfer for returning visitors (GB) x 0.81kWh/GB x 0.25 x 2
Therefore, E = Energy consumed for first time visitors + Energy consumed for returning visitors
C = E x 442 g/kWh (or alternative/region-specific carbon factor)
AE = E x Monthly Visitors x 12
AC = C x Monthly Visitors x 12
Source for this calculation: https://sustainablewebdesign.org/calculating-digital-emissions/
end tl;dr
It is evident from the above computations that volume of data transferred to your browser is the only variable that directly influences your websites' carbon footprint.
Volume of Data includes volume of CSS, JS, Fonts, as well as dynamic data interactions like form posts or restful api requests.
There are a few improvements you can do to make your website better.
Interestingly, these all factors also improve your websites' performance too.
If your website uses images, then consider optimizing them. few of the ways of optimizing can be
There's a good set of advise available here: https://web.dev/fast/#optimize-your-images
Custom fonts can be heavy. Don't use too many custom fonts
Your CSS which loads on the top of your page often is the most performance deterrant.
Minimising JS code and appropriate chunking mechanism ensures that only the relevant JS bundle loades on the page. Good news is, almost all the modern JS based web development framworks does this intelligently. If you're using create-react-app, you can influence the code chunking with react.lazy() and Suspence.
Cookies are often unavoidable. However, developers in many cases store data in cookies. This should not be done, as cookies travel in request headers, and add on to the network loads. Similarly, custom headers should be discouraged, as they add up to network load.
Appropriate caching headers ensures that browsers don't make repeated roundtrips to server to get content. Ensure that you have set an appropriate cache longivity, so that the content, once served, gets cached in browser. This is particularly useful for returning visitors to your site.
Compression headers ensure that data is compressed while served to browsers. gzip is the most common option and all api gateways and content delivery networks support this. brotli is better option, although it is not that popular yet.
On AWS stack s3 and cloudfront, combined with brotli and cache-control headers can make a very powerful content delivery mechanism.
UX and Design plays a crucial role in reducing network load. There are a few places where Design can solve reduce the network loads.
If you're making a public website, then the design must support mobile phone and other handheld devices. And in such devices the screen real estate is really small. Therefore, a lot of data transfer can be optimized for such devices. for eg.
Supporting Dark Mode in UI, although may not affect the network load, but can be useful in significantly reducing power consumption of OLED based modern mobile devices. source
For Ecomm applications, a lot of digital marketing junk is loaded on UIs, through tag management channels, and users often do not have control on those. These not only adds on to the network traffic, but often a risk to privacy as well. Often, this data capture is useful in order to support users but the website provider must minimize the data capture, and make every attempt to reduce network load.
Its true that attempting to reduce carbon footprint also improves your web applications performance to a great extent. However, there are a few scenarios where network load and performance may not go hand in hand. A pragmatic approach is necessery to address such situations.