Building a Greener Web

A presentation at All Day Hey in May 2023 in Leeds, UK by Michelle Barker

Slide 1

Slide 1

Building a greener web Web sustainability for designers and developers

Slide 2

Slide 2

css-irl.info

Slide 3

Slide 3

Senior Front End Developer at

Slide 4

Slide 4

Slide 5

Slide 5

3.7% of worldwide C02e emissions https://bbc.in/35mLuxM

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Photo: pexels.com/@brett-sayles

Slide 10

Slide 10

Slide 11

Slide 11

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Device manufacture Infrastructure Device use

Slide 15

Slide 15

2 MB Average web page size https://bit.ly/3rIfZWc

Slide 16

Slide 16

Fast websites Low-carbon websites

Slide 17

Slide 17

WebPageTest

Slide 18

Slide 18

WebPageTest PageSpeed Insights

Slide 19

Slide 19

WebPageTest PageSpeed Insights GTMetrix

Slide 20

Slide 20

Core Web Vitals LCP Largest Contentful Paint FID First Input Delay CLS Cumulative Layout Shift

Slide 21

Slide 21

Carbon budgets

Slide 22

Slide 22

websitecarbon.com

Slide 23

Slide 23

Slide 24

Slide 24

ecoping.earth

Slide 25

Slide 25

digitalbeacon.co

Slide 26

Slide 26

Images

Slide 27

Slide 27

43% 30% Bytes transferred Requests Source: https://httparchive.org/reports/page-weight

Slide 28

Slide 28

Use fewer images

Slide 29

Slide 29

Use fewer images Use smaller images

Slide 30

Slide 30

556kb 326kb -41% Photo: unsplash.com/@aarngiri

Slide 31

Slide 31

Use fewer images Use smaller images Optimise

Slide 32

Slide 32

326kb 100kb -69% Photo: unsplash.com/@aarngiri

Slide 33

Slide 33

Use fewer images Use smaller images Optimise Serve the right images for the user’s device

Slide 34

Slide 34

Use fewer images Use smaller images Optimise Serve the right images for the user’s device Use modern image formats (WebP, AVIF)

Slide 35

Slide 35

<picture> <source type=”image/webp” srcset=”robin.webp 400w…” sizes=”(min-width: 1200px) 50vw, 100vw”> <img srcset=”robin.jpg 400w…” src=“robin.jpg” sizes=”(min-width: 1200px) 50vw, 100vw” alt=”…”> </picture>

Slide 36

Slide 36

Use fewer images Use smaller images Optimise Serve the right images for the user’s device Use modern image formats (WebP, AVIF) Lazyload

Slide 37

Slide 37

<img srcset=”…” src=”robin.jpg” alt=”…” loading=”lazy” />

Slide 38

Slide 38

Fonts

Slide 39

Slide 39

Use fewer fonts

Slide 40

Slide 40

Use fewer fonts Consider variable fonts

Slide 41

Slide 41

Slide 42

Slide 42

Use fewer fonts Consider variable fonts Use modern font formats (e.g. WOFF2)

Slide 43

Slide 43

ff github.com/google/wo 2

Slide 44

Slide 44

Use fewer fonts Consider variable fonts Use modern font formats (e.g. WOFF2) Subset fonts

Slide 45

Slide 45

w3.org/TR/IFT

Slide 46

Slide 46

Use fewer fonts Consider variable fonts Use modern font formats (e.g. WOFF2) Subset fonts Self-host

Slide 47

Slide 47

gwfh.mranftl.com/fonts

Slide 48

Slide 48

Third-party embeds

Slide 49

Slide 49

Slide 50

Slide 50

Avoid embeds

Slide 51

Slide 51

Avoid embeds Defer loading if possible

Slide 52

Slide 52

Avoid embeds Defer loading if possible Lazyload

Slide 53

Slide 53

Avoid embeds Defer loading if possible Lazyload Import on interaction

Slide 54

Slide 54

github.com/paulirish/lite-youtube-embed

Slide 55

Slide 55

Avoid embeds Defer loading if possible Lazyload Import on interaction Don’t use Google Analytics

Slide 56

Slide 56

withcabin.com

Slide 57

Slide 57

usefathom.com

Slide 58

Slide 58

aremythirdpartiesgreen.com

Slide 59

Slide 59

Not all bytes are created equal

Slide 60

Slide 60

Use less Javascript

Slide 61

Slide 61

© Andy Bell andy-bell.co.uk

Slide 62

Slide 62

Design for less JS

Slide 63

Slide 63

Design for less JS Use native APIs

Slide 64

Slide 64

Design for less JS Use native APIs Do you need to transpile?

Slide 65

Slide 65

Design for less JS Use native APIs Do you need to transpile? Do you need a framework?

Slide 66

Slide 66

Slide 67

Slide 67

Optimise all the things

Slide 68

Slide 68

Caching

Slide 69

Slide 69

bit.ly/40B38ou

Slide 70

Slide 70

Caching fi Mini cation and compression

Slide 71

Slide 71

Caching Mini cation and compression fi Tree-shaking

Slide 72

Slide 72

Caching Mini cation and compression Tree-shaking fi Code splitting

Slide 73

Slide 73

Static import import { Auth } from “@aws-amplify/auth”; const user = Auth.currentAuthenticatedUser();

Slide 74

Slide 74

Dynamic import import(“@aws-amplify/auth”).then(({ Auth }) => { const user = Auth.currentAuthenticatedUser(); });

Slide 75

Slide 75

Caching Mini cation and compression Tree-shaking Code splitting fi Dependency auditing

Slide 76

Slide 76

Device manufacture Infrastructure Device use

Slide 77

Slide 77

Device manufacture Infrastructure Device use

Slide 78

Slide 78

Device manufacture Infrastructure Device use

Slide 79

Slide 79

Device manufacture Infrastructure Device use

Slide 80

Slide 80

Low-energy colour scheme

Slide 81

Slide 81

User journey

Slide 82

Slide 82

Device manufacture Infrastructure Device use

Slide 83

Slide 83

Renewable energy

Slide 84

Slide 84

thegreenwebfoundation.org/directory

Slide 85

Slide 85

Timing

Slide 86

Slide 86

branch.climateaction.tech

Slide 87

Slide 87

branch.climateaction.tech

Slide 88

Slide 88

Location

Slide 89

Slide 89

Case study: UsTwo https://bit.ly/3N8uWgD

Slide 90

Slide 90

Case study: UsTwo 0.54gCO2e https://bit.ly/3N8uWgD 0.02gCO2e

Slide 91

Slide 91

45% 99% to carbon reduction

Slide 92

Slide 92

greensoftware.foundation

Slide 93

Slide 93

Developer tooling

Slide 94

Slide 94

“ If I was a better programmer, I’d write a script that shows you the cumulative CO₂ you’ve generated every time you type npm install . Eric Bailey https://bit.ly/3KH98VI

Slide 95

Slide 95

Consider a static site

Slide 96

Slide 96

Consider a static site Don’t run optimisations in development

Slide 97

Slide 97

Consider a static site Don’t run optimisations in development Remove unused dependencies

Slide 98

Slide 98

Consider a static site Don’t run optimisations in development Remove unused dependencies Reduce complexity

Slide 99

Slide 99

“ Shaving o a single kilobyte in a le that is being loaded on 2 million websites reduces CO2 emissions by an estimated 2950 kg per month. Danny van Kooten fi ff https://bit.ly/3nX93Up

Slide 100

Slide 100

Why do our individual actions matter?

Slide 101

Slide 101

Unfortunately, capitalism Photo: pexels.com/@pixabay

Slide 102

Slide 102

Amplify our voices

Slide 103

Slide 103

Lead by example

Slide 104

Slide 104

Regulation

Slide 105

Slide 105

“ Cultural revolutions don’t happen because of systems change; they happen when a group of people voice a compelling story that propagates across society and becomes a social norm. https://bit.ly/3nZs48x

Slide 106

Slide 106

Networks

Slide 107

Slide 107

Elon Musk isn’t going to solve climate change

Slide 108

Slide 108

Form a workplace action group Support each other to take climate action Push the climate agenda and greener practices within your organisation Share resources Hold each other accountable

Slide 109

Slide 109

Share your learning Write Speak at events Share on social media

Slide 110

Slide 110

Slide 111

Slide 111

w3.org/community/sustyweb

Slide 112

Slide 112

Recognising our power + privilege

Slide 113

Slide 113

Slide 114

Slide 114

https://bit.ly/35HxOxx

Slide 115

Slide 115

Sometimes less is more

Slide 116

Slide 116

Reasons to be hopeful

Slide 117

Slide 117

Slide 118

Slide 118

Slide 119

Slide 119

“ Hope doesn’t preclude feeling sadness or frustration or anger… Hope is not optimism. Hope is a discipline… we have to practice it every single day. Mariame Kaba https://bit.ly/3Noy2NK

Slide 120

Slide 120

planet