In a world where people are willing to destroy our (only) planet for profit without providing something in return (looking at you NFTs 👀), we, as developers, are responsible for the sustainability of what we create or contribute to.
“If the Internet was a country, it would be the 7th largest polluter”
~ Sustainable Web Manifesto
There are at least three parts on reducing your website's carbon emissions: Host, Code & Content.
Host: Hosting your website on a host that uses renewable energy can decrease its CO2 emissions significantly. The Green Web Foundation has collected a huge list of them. Additionally, it has created many tools utilizing them, including the Green Web Check tool.
Content: Images are the biggest offenders to the amount of data clients need to download when visiting a website. Compressing them, reducing the amount used and replacing them with SVGs (if possible of course) will all contribute against it. After that, ADs, tracking, other media (eg. sounds & videos) and fonts increase the total data transferred by a lot.
On the action side of things, the action uses lighthouse to get the amount of transferred data which then passes through some calculations to get the amount of CO2 it produces per visit. The Green Web Foundation's API is also used (if set to true) to determine whether the host is using renewable energy. Lastly, some additional calculations are being done to generate some fun facts about it before logging it in the action output & create comments on the commit or PR that caused it to run. This all happens inside a docker container for two reasons: 1) GitHub uses at max node12 (Current LTS is 16) plus dependencies are being bundled in the repo (which increases its size and makes development difficult). 2) lighthouse requires a browser to run which is far easier and less time consuming to just install in the docker image.
name: Calculate CO2 🌱 on: [push, pull_request] jobs: audit: runs-on: ubuntu-latest steps: - name: Calculate CO2 🌱 uses: GeopJr/CO2@v1 with: url: "https://geopjr.dev/" renewable: true
Reasoning: Reducing your website's carbon emissions is just as important as running tests. Accepting a PR or commiting code that increases them by eg. 20% is irresponsible and should be prevented as soon as possible.
A GitHub action that notifies you about your website's carbon emissions and gives you some fun facts about it
🌱 CO2 🔥
Get notified about your website's carbon emissions using GitHub Actions
How does CO2 (the action) work?
CO2 (the action) will calculate your website's carbon emissions based on the amount of data it transfers to the client, as well as notify you if your host is using renewable or bog standard energy, along with how much CO2 you could not emit by switching to one that uses renewable energy (if not on one already) Some fun (or not so fun) facts about it in the long run will also be included!
To stay on par with Website Carbon Calculator without spamming their API, the same functions happen locally This includes their calculations as well as their way of getting the amount transferred data (lighthouse).
The renewable energy data is provided by the The Green Web Foundation, however since it relies on an external API, it is disabled…
The repo README includes workflows for connecting Vercel & Netlify previews with the action as well as some interesting action conditions.
The renewable energy check is being done by The Green Web Foundation.
(there's more on the repo)