sustainability
v0.6.1
Published
Digital Sustainability Audits
Readme
Digital Sustainability Audits
A new methodology for assessing the Internet carbon footprint and sustainability of digital services. Computes the carbon footprint (CF) index, determines the energy source of servers, the usage of HTTP2.0, WebP image format, lazy loading on images, font subsetting, etc. Effectively generates a customized sustainability report with a set of helpful comments to reduce the CF.
Problematic
Increasing Internet connectivity in everyday life fosters new, or otherwise more energy-intensive, forms of demand that may counterbalance energy savings [1]. As example, the rising of web applications and websites. They provide an engaging user experience with the development of a wide range of functionalities and interactive elements but still, they may have an impact on the environment.
Our solution
Digital Sustainability Audits (DAS) is our solution for an environmentally sustainable transformation of digital resources.
Some of its key features are:
- Automated
- Lighting fast
- Platform agnostic
- Extensible
- User & developer friendly
How it works
With the help of several audits or test suits we are able to assess digital sustainability of any service with only one thing: a valid URL.
At this moment, audits are divided into two categories: server and design.
Server audits
Server aspects which are essential for online sustainability.
Design Audits
Targets the website assets that convert code to user consumable content.
Are you ready to try it?
- Jump right into the demo part and see it by yourself!
Or stay for getting to know better the architecture with our diagrams.
Basic architecture
To better know what exactly does sustainability in the background for each run, please refer to here.
Try it now
User Interface
Visit the site https://audits.digital, enter a URL and wait for the report to be generated for you. That's it.
Install puppeteer (if you don't already have it installed):
npm i puppeteer
Install sustainability locally:
npm i sustainability
Now you can use it on your Node.js application. Take as example the following code:
const { Sustainability } = require("sustainability");
const url = "https://www.example.org";
(async () => {
const report = await Sustainability.audit(url);
console.log(report);
})();sustainability [opts] url
Which produces the following report object:
{
globalScore: 88,
meta: {
id: '4c21fbb0-ba35-11ea-bd32-09a6ce997b13',
url: 'https://www.example.org',
timing: [ 1593454566154, 1593454568225 ]
},
audits: [
{ category: [Object], score: 75, audits: [Object] },
{ category: [Object], score: 100, audits: [Object] }
]
}You can pull the latest trydas/sustainability docker image from this repository
Note that you will also need to have a local installation of Redis or a running docker image.
Environment variables
- REDIS_HOST (default to 127.0.0.1)
- REDIS_PORT (default to 6379)
- FRONTEND_URL (for setting up CORS, default to '*', defaults to null when
NODE_ENV=productionis set) - REDIS_URL (default to unset)
With docker compose
- Run docker-compose file in the root docker folder.
cd docker/
docker-compose up -dOpen up a web browser and visit
http://localhost:8081Enter a url and run audits
class: Sustainability
Sustainability module provides a method to run the sustainability audits on a URL.
URL<[string]> A valid and reachable URL to evaluate. Warning: You are responsible for providing a valid URL.settings<[Object]> Set of configurable settings for the audit. May include the following optional fields:browser<Browser> Your own puppeteer's browser instance. If you set this options, the API won't spawn a browser instance. This may be useful if you want to make use of thelaunch.connect(wsEndpoint)method to remotely run a headless browser and pass it to the API. Warning: You will be responsible for handling the browser instance.launchSettings<[Object]> passed to puppeteer.launch. Refer to Puppeteer documentation for more information. Defaults to{}.connectionSettings<[Object]> Set of configurable connection settings. May include the following fields:maxNavigationTime<[number]> Specifies a timeout in milliseconds (ms) for all the tasks. Defaults to 60000ms.maxScrollInterval<[number]> Specifies the scrolling interval in milliseconds (ms) in the function that determines lazy loaded images. Defaults to 30ms.emulatedDevice<[Object]> Set of emulated device settings. May include the following fields:userAgent<[string]> A user-agent string.viewport<[Object]> Set of viewport settings. May include the following fields:width<[number]>height<[number]>
name<[string]> Optionallocation<[Object]> Set of location settings. May include the following fields:name<[string]> The location name.latitude<[number]> Latitude between -90 and 90longitude<[number]> Longitude between -180 and 180accuracy<[number]> Optional non-negative accuracy value
coldRun<[boolean]> Should initialise a cold run to find any potential URL redirect. Defaults to true.streams<[boolean]> Should push individual audits results as they go. Defaults to false.
A readable stream of audits to pipe from. Used in combination with streams option.
For example:
(async () => {
Sustainability.auditStream.pipe(process.stdout);
await Sustainability.audit(url, {
connectionSettings: { streams: true },
});
})();You can enable verbose logging to see the API in action.
This is done by setting the DEBUG environmental variable to sustainability:*. or with the -d option in the CLI.
For example:
# Linux
DEBUG=sustainability:* node index.js
# Windows Powershell
$env:DEBUG=sustainability:* node index.jsContributions are welcomed
This is open-source software. We highly encourage everyone interested to help pushing up this project.
Core development? Join the team! Make sure you read first the contributions-dev notes.
Found and issue, visibility, business aspects, sharing your thoughts? Open a new issue
Sponsoring? Help us to keep the project running in Open Collective.
License
All the code and documents are licensed under MIT.
Useful links
- [1] https://doi.org/10.1016/j.erss.2018.01.018.
- DAS video https://www.youtube.com/watch?v=3kDEQy2p4NY
