Get segment-level results

Overview

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:

  1. the use-phase energy of datacentres serving content
  2. the use-phase energy network transfering the data
  3. the use-phase energy of user device an user is accessing content on
  4. the total embodied energy used to create all of the above

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.

Methodologies

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.

Learning goals

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:

  • How to return a breakdown of emissions by system segment when using the Sustainable Web Design Model

Setting up

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

Initialise CO2.js

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);

Output

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:

  • The emissions for each system segment's first and return visit (since we are using the perVisit function).
  • The total carbon emissions for our calculation.

Wrapping up

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: