Skip to content

philsturgeon/website-carbon-calculator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Website Carbon Calculator

Estimate your web page carbon footprint

Installation

$ composer require akhela/website-carbon-calculator

API

Estimate web page carbon footprint

View the Google documentation to generate a Google Pagespeed Api Key

$websiteCarbonCalculator = new WebsiteCarbonCalculator('GooglePagespeedApiKey');
$websiteCarbonCalculator->calculateByURL('https://www.websitecarbon.com/how-does-it-work/')

Output

{
  "url": "https://www.websitecarbon.com",
  "isGreenHost": true,
  "bytesTransferred": 135289,
  "networkRequests": 16,
  "performanceScore": 0.94,
  "loadingExperience": "FAST",
  "domSize": 308,
  "speedIndex": 934,
  "firstMeaningfulPaint": 491,
  "interactive": 692, 
  "bootupTime": 94,
  "serverResponseTime": 150,
  "mainthreadWork": 762,
  "energy": 0.000171,
  "co2PerPageview": 0.0739
}

For better performance, detect hosting energy type and store it in a database to avoid repetitive call to The Green Web Foundation.

Detect hosting energy type

$isGreenHost = WebsiteCarbonCalculator::isGreenHost('https://www.websitecarbon.com')
$websiteCarbonCalculator->calculateByURL('https://www.websitecarbon.com/how-does-it-work/', ['isGreenHost'=>$isGreenHost])

How does it work

Calculating the carbon emissions of website is somewhat of a challenge, but using five key pieces of data we can make a pretty good estimate:

  • Data transfer over the wire
  • Energy intensity of web data
  • Energy source used by the data centre
  • Carbon intensity of electricity
  • Website traffic

Under the hood, it uses Google pagespeed api and The green web foundation api

Website Carbon Calculator

The internet consumes a lot of electricity. 416.2TWh per year to be precise. To give you some perspective, that’s more than the entire United Kingdom.

From data centres to transmission networks to the devices that we hold in our hands, it is all consuming electricity, and in turn producing carbon emissions.

This project is widely inspired by the Website Carbon Calculator algorithm 2.0 and The Green Web Foundation co2.js

Glossary

Tests

Run tests

$ pagespeedApiKey=xxxxxx php vendor/bin/phpunit

About

Estimate your web page carbon footprint

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%