website carbon calculator formula
carbon.ts
49 lines 1.2 kB view raw
1// derived from https://sustainablewebdesign.org/estimating-digital-emissions/ 2 3const GRID = 494; // in gCO2e/kWh 4 5// operational energy intensity (kWh/GB) 6const OP = { dc: 0.055, net: 0.059, ud: 0.08 }; 7 8// embodied energy intensity (kWh/GB) 9const EM = { dc: 0.012, net: 0.013, ud: 0.081 }; 10 11// this function uses some defaults from the spec. 12// green hosting factor is prob the most important 13// one to change here 14function estimateEmissions( 15 bytes: number, 16 { 17 greenHostingFactor = 1, 18 returnVisitorRatio = 0, 19 dataCacheRatio = 0.02, 20 } = {}, 21) { 22 const newVisitorRatio = 1 - returnVisitorRatio; 23 const gb = bytes / 1e9; 24 25 // operational emissions data centers 26 const OPDC = gb * OP.dc * GRID * (1 - greenHostingFactor); 27 28 // embodied emissions data centers 29 const EMDC = gb * EM.dc * GRID; 30 31 // operational emissions networks 32 const OPN = gb * OP.net * GRID; 33 34 // embodied emissions networks 35 const EMN = gb * EM.net * GRID; 36 37 // operational emissions user devices 38 const OPUD = gb * OP.ud * GRID; 39 40 // embodied emissions user devices 41 const EMUD = gb * EM.ud * GRID; 42 43 const perVisit = OPDC + EMDC + OPN + EMN + OPUD + EMUD; 44 45 return ( 46 perVisit * newVisitorRatio + 47 perVisit * returnVisitorRatio * (1 - dataCacheRatio) 48 ); 49}