Grid intensity polyfill
A polyfill, to build awareness of carbon intensity into javascript programs - move your code through time and space for greener digital products.
The dream is for this to be built into the browser, so we learn as web makers to do the right thing by default, and incorporate carbon-aware practices into how we work. Partly inspired by the work by Michelle Thorne and Yulia Startsev on Firefox Eco Mode concepts and sustainablity engineering, and by Lucia Ye's recent work on Onlign OS, and David Sykes work on the energy onion model, and Auke Hoekste's work on energy systems as ecosystems
Usage
import GridIntensity from '@tgwf/grid-intensity-polyfill'
grid = GridIntensity()
const carbonIndex = await grid.getCarbonIndex()
if (carbonIndex == 'low') {
loadrichImages()
await Promise.all([
doExpensiveOperation(), preLoadVideo()
])
} else {
loadLiteImages()
queueJobforWorker([
doExpensiveOperation
fetchVideo
])
}
Quick demo
There's a public demo in the github repo, to try this out. Run these commands after checking the code to see it
npm run build
cp ./lib/gridintensity.browser.js ./lib/gridintensity.browser.min.js ./public
npx run serve public
Background
We know that the internet runs on electricity. That electricity comes from a mix of energy sources, including wind and solar, nuclear power, biomass, fossil gas, oil and coal and so on,
We call this the fuel mix, and this fuel mix can impact on the carbon intensity of your code.
Move your code through time and space
Because the fuel mix will be different depending when and where you run your code, you can influence the carbon intensity of the code you write by moving it through time and space - either by making it run when the grid is greener, or making it run where it's greener, like a CDN running on green power.
This API is designed to make that easier. It pulls data from open data sources, about the predicted carbon intensity of energy on the grid where code is run, and presents an object you can query, so you can make an application or website serve a different experience to end users based on the carbon intensity.
TODO
This is very incomplete. Sorry about that. I hope this gives an idea of where you can help if you're interested.