There are a few different models that can be used to measure digital carbon emissions. CO2.js includes two of these - the OneByte model, and the Sustainable Web Design model. This guide will show you how use the different carbon estimation models available in CO2.js.
This guide will not go into the details of each model. If you'd like to learn more about the OneByte or Sustainable Web Design models then take a look at Methodologies for calculating website carbon.
Since v0.11.0, CO2.js uses the Sustainable Web Design model by default. After importing CO2.js into your project, you can start using this model right away by initiating a co2()
object. Alternately, you can pass in the model: "swd"
option.
import { co2 } from '@tgwf/co2'
const swd = new co2()
// You can also explicitly declare the model
const declaredSwd = new co2({ model: "swd" })
If you want to use the OneByte model, then you'll need to let CO2.js know. This can be done by passing in a model
parameter with a value of "1byte"
when you initiate a new co2()
object.
import { co2 } from '@tgwf/co2'
const oneByte = new co2({ model: "1byte" })