What makes a website green? A guide for front end devs
Tags: webdev, design, programming, html
Published: 2021-06-30 08:04:32

A friend sent me a message with a simple question ‘why is this website considered green?’ All I could answer was well I went on [Website Carbon](https://www.websitecarbon.com/) and it told me that the website is green. 

My own answer was not enough for me so I dug in.

You’d think that the answer would be a simple ‘Because x, y, & z’ but like everything that tackles complex systems, and human carbon footprint is an incredibly complex system, I had to go with ‘well let me start at the beginning.’ 

*So let’s start at the beginning: what makes a website green?*

-----
If the internet where a country and all of us online it's citizens it would be the [4th most carbon consuming country](https://internethealthreport.org/2018/the-internet-uses-more-electricity-than/) after China, USA and India by 2025, and the wider [IT sector would be the 3rd] (https://www.climatecare.org/resources/news/infographic-carbon-footprint-internet/) (after China & USA). The internet and tech by different calculations account for [2](https://www.ovoenergy.com/blog/green/the-carbon-footprint-of-the-internet.html) to [4%](https://www.webfx.com/blog/marketing/carbon-footprint-internet/) of carbon emissions ([the airline industry pre pandemic was responsible for 2%](https://www.atag.org/facts-figures.html))

Of course one can argue about the overlap and differences between IT and the Internet. But to keep some order and sanity lets narrow this blogpost to carbon emission of the internet. 

So to answer the seemingly basic question 'What makes this website green?' we should first answer the question 'How do we calculate the carbon emission of a website?'

### How do we calculate the carbon emission of a website?

As a developer I am proficient at copy pasting and the folks at Website Carbon created a handy list of what they consider when they [calculate the carbon footprint of individual websites](https://www.websitecarbon.com/how-does-it-work/): 

* Data transfer over the wire - amount of energy it takes to load the website
* Energy intensity of web data - "Energy is used at the data centre, telecoms networks and by the end user’s computer or mobile device." [Website Carbon calculated an average](https://www.websitecarbon.com/how-does-it-work/) of 1.8kWh/GB.
* Energy source used by the data centre - the [Green Web Foundation](https://www.thegreenwebfoundation.org/) database is checked 
* Carbon intensity of electricity - carbon footprint of grid electricity 
* Website traffic - if the website has 1 million users it's a bigger polluter than a website that gets 1 visit.  

As web developers we have **some** control over:
* Data transfer over the wire 
* Energy intensity of web data- incredibly limited control
* Energy source used by the data centre - if it's a personal project we have full control over this and can choose a 'green' hosting platform. 


### Why should devs be more green?

For one because we live here on Earth and I like to keep my home clean. And second, though developer salaries are good I am not sure we earn enough to get ourselves to Mars when Earth goes belly up. 

Third reason is that becoming a carbon conscious developer makes us better developers (see the 1996 and 2021 SpaceJam websites comparison bellow). More importantly developers don't just have control over our own projects but some control over some of the largest websites on the planet and we are often the group that is heard within corporations (not always but often).

As a disclaimer I should add that this is by no means an attempt to put responsibility for the current climate mess on the internet. Climate change is essentially a high stakes blame game of who farted where [everyone farted](https://www.youtube.com/watch?v=ipVxxxqwBQw). 

As a second disclaimer I am a front end developer not a scientist, so this is advice that is meant to be practical rather than preachy. 

**So what can be done to make a website more green?**

-----
## What is Data Transfer over the wire?

Tom Greenwood in his book ['Sustainable Web Design'](https://abookapart.com/products/sustainable-web-design) put it best:

*“Most researchers use kilowatt-hours per gigabyte (kWh/GB) as a metric of energy efficiency when measuring the amount of data transferred over the internet when a website or application is used. This provides a great reference point for energy consumption and carbon emissions. As a rule of thumb, the more data transferred, the more energy used in the data center, telecoms networks, and end user devices.*

*For web pages, data transfer for a single visit can be most easily estimated by measuring the page weight, meaning the transfer size of the page in kilobytes the first time someone visits the page. It’s fairly easy to measure using the developer tools in any modern web browser. Often your web hosting account will include statistics for the total data transfer of any web application.”*

In other words the more requests, images, videos, music your website has the more data is needed to load it. Back in the early days of the web, developers where conscientious of this as internet speed was really really slow and media heavy websites took forever to load, today speed is not an issue and to be honest we (developers) did get sloppy. 

Possibly the best examples of this are the [iconic](https://www.spacejam.com/1996/) and the [new](https://www.spacejam.com/) SpaceJam websites. Just pop over to the network tab of your developer tools and compare the amount of data the old and the new websites use.
3.1kb vs 1.6mb as a reminder 3.1kb is only 0.0031mb (1.6mb is 1,600kb). The old website takes a fraction of energy compared to the new one. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ae4wetpnuckds3tt9fz5.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aodwxpeaq4yw0a5ffvh5.png)

-----
## How to decrease Data transfer over the wire?

### Video 
The advice for video is - avoid video on your website. One study found that streaming videos on YouTube produces approximately [10 kg of CO2 per hour](https://www.bristol.ac.uk/news/2019/may/rethinking-digital-service-design-.html) or the same amount as Glasgow a city with a population of half a million. 
If you really need to use video then:
* use [SD by default rather than HD](https://vimeo.com/539975337)
* avoid video autoplay. This is good for the planet and also for the user as the user has to confirm that they actually want to watch the video.(from Sustainable Web Design by Tom Greenwood)

### Images
Images are where most of us get lazy. Because internet speed is so good the load time between a 1mb image and a 300kb is unnoticeable to most users. And if it's just one image the climate impact is not that bad but what if it's one image on a website that is visited by thousands of people each day? What if its thousands of images on a website visited by thousands of people. Little things add up quickly. 

In fact the average weight of a website in [2010 was 500 kb in 2020 it was 2mb](https://docs.google.com/presentation/d/1LlmUR0Uoh4dgT3DjanLjhlXrk_5W2nJBDqDAMbhe8v8/edit#slide=id.gc0c4170507_0_7) that is a 4x increase and 50 % of that increase is because of images.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcd1es7756h3v01f5iac.png)

So what are the ways developers can deal with the image issue:
1.**Don't show** unless asked for or have a preview image and offer a large image only if the user explicitly asks for it. 

2.**Resize** - load an image that is the appropriate size for the device that the user is viewing it on. 

As an example you really do not need an 8000px x 45000px (resolution 300px/inch), when the average Macbook Pro is [2560 x 1600 at 227 pixels per inch](https://support.apple.com/en-us/HT202471) and the largest iPhone is [1284 x 2778 px](https://kapeli.com/cheat_sheets/iOS_Design.docset/Contents/Resources/Documents/index).

**[formafantasma]((https://formafantasma.com/works#))** - a design agency that focuses on art museums uses both of these tactics. Users are not shown the images unless they want to see more information about the project.

3.**format** - use an efficient image format
Lets face it most of us usually deal either with JPEG/JPG or PNG so which one is better? 
The rule of thumb is [for photographs use JPEG for graphics, logos or text heavy images use PNG](https://thrivethemes.com/jpeg-vs-png/).

But if we want to be green SVG is better than PNG for logos. And [JPEG is best substituted by WEBP or even better by AVIF](https://jakearchibald.com/2020/avif-has-landed/). Avif works like magic and is usually around 10x less than jpeg BUT major browsers like Safari do not support it.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wk6it7jeqbczeku6dy0.png)
* [convert Jpeg to WEBP](https://convertio.co/jpg-webp/)
* [convert Jpeg to AVIF](https://convertio.co/jpg-avif/)

4.**compress** - this is great for website optimisation as well as the environment. Here are some tools that can be used for lossless optimisation:
*[ShortPixel](https://shortpixel.com/)
*[Compressor](https://compressor.io/)
*[TinyPNG](https://tinypng.com/)
*[TinyJPG](https://tinyjpg.com/)

*Further listening/reading:*
[“The Joy of Optimizing Images”](https://aneventapart.com/news/post/the-joy-of-optimizing-images-by-una-kravets-aea-video) by Una Kravets
* [Lossless compression](https://en.wikipedia.org/wiki/Lossless_compression#:~:text=Lossless%20compression%20is%20a%20class,reconstructed%20from%20the%20compressed%20data.) -  can reconstruct the original exactly
* [Lossy compression](https://en.wikipedia.org/wiki/Lossy_compression) - information is lost but (most) users do not notice. 

**Low tech magazine** - compression and optimisation can work together as an interesting stylistic choice. For example images in [Low tech magazine](https://solar.lowtechmagazine.com/) fit really well with the design and vary in size between 100kb and 12kb which is by far smaller than the often advised upper limit for image size of [1mb (1000kb)](https://www.jimdo.com/blog/optimize-website-images-for-better-design-seo/#:~:text=Image%20size%3A%20The%20actual%20dimensions,be%20795%C3%97300%20pixels.) (1mb = 1,000kb)

5.**avoid special effects** - even “simple” effects can have a significant impact on the end users’ CPU usage. For example, adding a carousel to an image gallery instead of displaying static images on the page increased peak CPU usage by 7 percent. Adding a simple fade-in effect on page load increased peak CPU usage by 22 percent. (Excerpt From Sustainable Web Design by Tom Greenwood)


### Good navigation
Every-time a user navigates to a new page - it has to load, and loading a page takes up energy, hence the shorter the user journey - the more energy efficient it is. 
And to be honest this is just great user experience advice. As a user I loathe lengthy user journeys or even worse yoyo user journeys (where you pass the same page multiple times creating a bizarre digital Blair Witch project experience).  

### [Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
Caching means temporarily storing data. The best contenders for what you store are things that are unlikely to change or change infrequently. 
How you do caching will completely depend on your website, and its' best to google for your specific scenario and tools you are using.

There is possibly one scenario that most developers will come across - **caching fonts**. Most websites use third party fonts (specifically google fonts) and most choose their font once and never change it, so it's definitely [worth exploring how to get rid of that unnecessary request call](https://wpglorify.com/host-google-fonts-locally-levrage-cache/).  

[Offline website](https://chris.bolin.co/offline/) is possibly the most interesting experimental website that works only offline by caching (check the [github](https://github.com/chrisbolin/offline)) to show the website only when the user is offline. 

*Further reading:*
*[Frontend caching strategies](https://medium.com/@brockreece/frontend-caching-strategies-38c57f59e254)
*[A Hitchhiker’s Guide to Caching Patterns](https://dev.to/hazelcast/a-hitchhiker-s-guide-to-caching-patterns-1ghl)

### [Lazy loading](https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading)
A strategy that loads a resource at the point of use/only when its needed. 
Think of long scroll blog posts with images, with lazy loading the image at the top of the page loads instantly but all other images load only as the user scrolls down to see them.
There is [native lazy loading for img](https://dev.to/ben/native-lazy-loading-for-img-and-iframe-is-coming-to-the-web-55on) and iframe tags so really no excuse to not do it. 
Also the benefits don't just include a lighter page but it can also be [beneficial for SEO](https://yourmarketingpeople.com/blog/how-lazy-loading-images-can-benefit-your-seo/).

### API requests
*unnecessary requests - if you have to call an API to get data - you have to call an API there is no way around it. However it might be worth considering reducing API calls that are design rather than utility lead for example using default fonts like Ariel rather than Google Fonts (see caching above).
*break up into small chunks - consider the structure of the API. Do you really need to call all 1000 rows of data when you are planning to show only 10 rows on one page?

*Further Reading:*
[Delivering Large API Responses As Efficiently As Possible](https://apievangelist.com/2018/04/20/delivering-large-api-responses-as-efficiently-as-possible/)

## How to minimise energy intensity of web data

How much energy does it require for a user to run your website? There is definitely overlap with some stuff above. The more images your website uses, the more videos it streams the more energy your user's device will need to consume to use your website. 

However, there is one thing that does not make a difference to website loading times but if your user is using a device with an OLED it makes a difference - colour. 

### Colour Palette 
According to a report from [Google](https://www.zdnet.com/article/google-heres-why-dark-mode-massively-extends-your-oled-phones-battery-life/) the screen is the biggest single power draw on it's phones and that for devices with OLED displays, darker colours make a significant difference.

Here you have two choices:
1.create a dark mode version of your website. 
2.use darker colours in the design of your website. 

## Conclusions
Let's not be lazy and actually act on easy to follow small pieces of advice that add up to make a difference (if your website uses images that’s the easiest place to start with). 

This said I should probably practice what I preach and go update my side project website... 

Stay tuned for Part 2.

## Further reading 
[Sustainable Web Design by Tom Greenwood](https://abookapart.com/products/sustainable-web-design)
[World Wide Waste by Gerry McGovern](https://gerrymcgovern.com/books/world-wide-waste/)
[The impact of the digital industry](https://manifesto.co.uk/the-impact-of-the-digital-industry-series-intro/)
[Sustainable Web Design](https://sustainablewebdesign.org/)
[Sustainable Web Manifesto](https://www.sustainablewebmanifesto.com/)
[How to stop data centres from gobbling up the world’s electricity](https://www.nature.com/articles/d41586-018-06610-y)
[CO2 emissions on the web](https://dannyvankooten.com/website-carbon-emissions/)

### Tools
[Website Carbon](https://www.websitecarbon.com/)
[A green search](https://www.ecosia.org/?c=en)
[Page Weight Report](https://httparchive.org/reports/page-weight)
[Electricity Map](https://www.electricitymap.org/map)

### Cool carbon efficient websites
[Organic Basics](https://lowimpact.organicbasics.com/)
[Low Tech Magazine](https://solar.lowtechmagazine.com/)