The Sustainable Web Design Model is a methodology which provides a general framework that can be used to estimate a website's carbon emissions. It can be used to return a total value for carbon emissions related to the transfer of bytes. It can also be uses to extrapolate carbon emissions associated with different segments of the entire website system:
In this tutorial, you will learn how to return a breakdown of emissions for each segment using the Sustainable Web Design Model in CO2.js.
It is also worth noting that what we will cover in this tutorial only works with the Sustainable Web Design Model in CO2.js. Check out the Methodologies for calculating website carbon page to learn more about the model itself.
This tutorial assumes you are already familiar with how to install CO2.js and use it to perform simple carbon calculations.
In this tutorial you will learn:
You should already have CO2.js installed and setup in your project. If you do not, it is recommended you go through the Getting Started: NodeJS tutorial
To have CO2.js return segment-level emissions estimates you need to set a results
key with the value of "segment" when initialising CO2.js in your project.
const { co2 } = require("@tgwf/co2");
const co2Emission = new co2({ results: "segment" });
You can then use CO2.js as usual to perform a calculation. In the example below we're using the perVisit
function.
const bytesSent = 1000 * 1000 * 1000; // 1GB expressed in bytes
const greenHost = false; // Is the data transferred from a green host?
estimatedCO2 = co2Emission.perVisit(bytesSent, greenHost);
console.log(estimatedCO2);
Running the code above returns the object below:
# Output:
{
'consumerDeviceCO2 - first': 139.6278,
'consumerDeviceCO2 - subsequent': 0.9308520000000001,
'networkCO2 - first': 37.59210000000001,
'networkCO2 - subsequent': 0.25061400000000006,
'productionCO2 - first': 51.01785,
'productionCO2 - subsequent': 0.34011900000000006,
'dataCenterCO2 - first': 40.27725,
'dataCenterCO2 - subsequent': 0.268515,
total: 270.3051
}
You can see that it contains a breakdown of:
perVisit
function).total
carbon emissions for our calculation.You now know to how to use CO2.js to return segment-level carbon estimates when using the Sustainable Web Design Model.
From here you can:
perByte
function.perVisitTrace
or perByteTrace
function. You can read more about those in the Cusomtise website carbon calculations tutorial.