DEADScript: The Role Of JavaScript In Web Sustainability

Rate this content
Bookmark

In the web performance circles, we tend to closely watch paint times, blocking times, and so many more metric times, which all contribute to analyzing the user experience. In 2023, we have begun to pay more attention to metric tonnes. DEADScript is a presentation highlighting the resources we’re loading in modern development, and JavaScript’s unique role in this disquieting environmental dilemma.

21 min
05 Jun, 2023

Comments

Sign in or register to post your comment.

AI Generated Video Summary

This Talk discusses digital sustainability and the role of JavaScript in web sustainability. It highlights the impact of electricity carbon intensity and page weight on carbon footprints. The Talk also examines JavaScript's contribution to the carbon footprint on mobile devices and emphasizes the importance of reducing unnecessary requests. The introduction of the carbon control tool, which provides performance data and estimates carbon footprints, is also mentioned.

1. Introduction to Dead Script

Short description:

Good morning, DOM! I tend to talk about web performance and metrics at work. Today, I'm going to talk about the environment and sustainability, specifically digital sustainability with respect to JavaScript. Welcome to my talk, Dead Script, the role of JavaScript in web sustainability. This recording is on May 17, the anniversary of ECMA International.

Good morning, DOM! You know me, I like to greet the DOM each and every morning. But I'm also going to say good morning, Amsterdam, or should I call it GCE Europe West 4. That's what we call it at work, it's one of our zones. I thought that was kind of funny.

Anyhow, let me get right into it. I tend to talk about web performance a lot. It's a thing I do at work. It's the engineers that I talk to at work as well. And, you know, we'll cover things like, I don't know, Core Web Vitals, like that new vital that was announced like maybe three weeks ago or something like that. But I definitely do talk about metrics, because we're surrounded by metrics at work. So I'll talk about paint metrics. I'll talk about speed metrics. I'll also talk about timing metrics. But today I'm going to talk about metric tons. Huh? What could that be all about? Well, I'm going to talk about the environment. I'm going to talk about sustainability. And what do you think when you hear the words like environment and sustainability? What crosses your mind? Well, I'll be very frank and honest. My brother got a Tesla, and I'm a little jealous because it's really nice. So I mean, I've been thinking about this Ioniq 6, which is kind of iconic actually, by Hyundai. I love the shape. But you know what, let's get back to the matter at hand, which is sustainability. And specifically, we're going to talk about digital sustainability. And since this is the JS Nation conference, we're going to cover digital sustainability with respect to JavaScript.

So I'd like to welcome you to my talk, which I'm calling Dead Script, the role of JavaScript in web sustainability. Now, a little background. This is a recording on May 17, which is the anniversary of ECMA International, the body that was responsible for standardizing JavaScript. For those who might know, JavaScript was once called LiveScript for a hot minute. So I was like, Dead Script, LiveScript, I thought that was kind of interesting. Anyways, let's keep it moving. So my name is Henri.

2. Digital Sustainability and ICT

Short description:

You can find me on most socials under Henri Helvetica. I work at Catchpoint and talk about performance, especially Webpagetest. Digital sustainability is complicated, with many factors to consider. It relates to how electricity is generated and powers information and communication technologies (ICTs). ICTs use 7% of global electricity and are responsible for 4% of CO2 emissions worldwide. This exceeds the aviation industry and even some countries. We also need to discuss data centers, networks, and consumer devices, which are all part of ICT. Location is another important factor to consider.

You can find me on most socials under Henri Helvetica. I work at this amazing company called Catchpoint. And one of the things I do at Catchpoint is talk about performance, and certainly around this fantastic tool that we have, which is called Webpagetest, the standard and gold standard really of web performance testing. I'm from the greatest city on the planet, which is called Toronto in Canada. And I do a little bit of distance running. So I like to use the hashtag devs who run. So if you do run as well, feel free to use it.

All right, let's keep it moving. As I talked about moments ago, we are going to talk about sustainability today. What I didn't mention is that digital sustainability is actually kind of complicated. There are so many factors. It's a bit of like an inexact science. There are so many moving parts that have to be considered, like big and small. So sometimes you're not sure how to sort of fit it all into this quadratic equation. But we need to talk about it because it has to do a lot of the time with how the electricity is generated, and that factors into the bigger conversation that we're going to have today.

But that electricity is also what powers ICTs, which is information and communication technologies. What are those? Well, it's really all the sort of digital technologies that sort of surround you, or relies on cell phones, computers, laptops, TV, internet, Wi-Fi, etc, etc, etc. So ICT is really all around us. In fact, ICT makes up, or uses up, really, 7% of the electricity worldwide. Pretty impressive. In fact, they're responsible for about 4% of the CO2 emissions worldwide. That's more than the aviation industry, and, in fact, it's even more than some countries on their own. Pretty impressive. But in talking about that, we also need to talk about things like data centers, part of ICT, networks, and consumer devices. As I mentioned, the laptop that I'm recording this talk on, the cellphone that won't stop ringing during my presentation, I don't know. The TV that I watch during Netflix, or ESPN, or sports, whatever it is. That's all ICT, and we are surrounded by that. Another thing, a very important thing to consider is location. You know what they say, location, location, location, very important. Well, here's what I'm talking about.

3. Electricity Carbon Intensity and Page Weight

Short description:

Now, let's look at the carbon intensity of electricity in 2022. The darker areas represent dirty electricity, while the lighter areas indicate cleaner energy sources like solar and wind. Moving on, the G7 nations' carbon intensity of electricity shows Japan at the top for the wrong reasons, while Canada and France are the cleanest countries. Multiple ways to produce electricity exist, including burning fossil fuels for dirty electricity or using wind and solar for cleaner energy. These factors contribute to the carbon footprint, which is influenced by data centers and the resources they send to our devices. Digital sustainability is complex, and while there are debates about calculating carbon footprints, the page weight metric has been widely accepted as a close correlation to emissions.

Now, if you look at this map, it's a world map of the carbon intensity of electricity in 2022. What is the carbon intensity? Well, I'll tell you right now. It's a measure of how clean our electricity is. So basically, if you look at this map, the darker areas is where they're probably creating dirty electricity, and the lighter area is where they may have things like solar or things like wind energy, which is much cleaner. Now, that factors in, we're going to talk about that a little later on into your carbon footprint.

Now, let's look at this other chart here, which is the carbon intensity of electricity of the G7 nations. And you see Japan at the top, but for the wrong reasons. The cleanest countries here are Canada and France. You know, there's some really interesting stuff coming out of France, a lot of studies around emissions and whatnot, that kind of caught me off guard. I didn't know they're up on it like that, but good to know. Anyhow, let's keep it moving.

As I've been talking about, there are multiple ways to produce electricity. You can burn fossil fuels and have what we'll call dirty electricity, or like I said, wind and solar to make things a lot cleaner. And these things factor into your carbon footprint. Once again, the inexact science. So that electricity powers the data centers that we use. The data centers that send the resources down the wire to the devices that we use. And ultimately, all of that factors in to the carbon footprint, which is what we're going to talk about today. But as I mentioned earlier, digital sustainability is actually kind of complicated. There have been very spirited discussions, sometimes arguments, about how to factor in some of these other elements into the carbon footprint calculations. But ultimately, many have agreed to one particular metric. Again, not the best, but one that correlates closest, or very well, to carbon footprints and emissions. And what that is, is the page weight. A page weight, pardon me, the page weight has been a classic performance metric. It's been around for quite a while. It's one of the easiest ones to tabulate. It's the amount of resources coming down the wire, and we figure out if it's this many kilobytes, or this many megabytes. Hopefully not. But that correlates very well with the... The page weight correlates very well with the carbon emissions, and we're gonna talk about that today.

4. JavaScript's Impact on Carbon Footprint

Short description:

Today, we'll examine data on JavaScript's impact on the carbon footprint, specifically on mobile. At the 75th percentile, a 4MB page emits 1.38 grams of CO2. JavaScript sent at this percentile is around 857 kilobytes. At the 90th percentile, over a megabyte of JavaScript is sent. Additionally, 40% and 44% of JavaScript at the 75th and 90th percentiles, respectively, is unused. This wasteful data contributes to the environmental impact.

What we're gonna do today is look at some data, and specifically we're gonna look at data with regards to JavaScript, and we're gonna see how and where JavaScript factors in to the carbon footprint conversation.

All right, let's go. Now, just a little heads up, everything that... All the data that I'm gonna share today is really on mobile, and I bring this up all the time because society has pretty much told us that we are on mobile pretty much all the time. So, a lot of the data that I'm sharing today is really with respect to mobile.

So, let's go. So, let's look at the page weight at the 75th percentile. It's just pretty much 4 megabytes. Alright, little big size, it's on the big side, but it's really there to start to paint the picture. Now, if we were to look at the carbon emissions at said percentile P75, we're looking at 1.38 grams of CO2 at the 75th percentile. So, now we can start to see that, okay, 4 megabyte page, 1.38. Alright, we kind of see what's going on.

Now, at the 75th percentile, again, JavaScript is being sent down the wire at 857 kilobytes. Alright, almost a meg of JavaScript at the 75th percentile. At the 90th percentile, we are sending well over a meg. In fact, we're sending 1,367 kilobytes. By the way, these stats are coming out of the HP archive. Fantastic trove of data that you should be reading, by the way, but we can now start to see the amount of JavaScript that we're sending down the wire.

Now, another important conversation is the fact that we can see unused JavaScript, as well, going down the wire. So, at the 75th percentile, 40% of the JavaScript down the wire is actually unused. Incredible. So, to follow that up, at the 90th percentile, we're seeing 44% of JavaScript going down the wire being unused. Again, what does that mean? We're sending it down the wire. We're parsing it, but it's sitting there with nothing to do. So, we're looking at wasteful data. In fact, at the 90th percentile, we are seeing more unused JavaScript than JavaScript coming down the wire at the 50th percentile. All right. So, once again, I'm sort of painting this picture that there's a lot of unused JavaScript going down the ... Coming down the wire on top of the fact that we're sending a lot of JavaScript down the wire, period. And believe me, there's much more.

5. The Impact of Requests on Sustainability

Short description:

The greenest request is the one that's never made. At the 75th percentile, there are 37 requests for JavaScript alone. At the 90th percentile, there are 62% more requests. The UK government and the European Union are prioritizing sustainability and partnering with like-minded businesses. Starting in 2024, large organizations will be mandated to provide sustainability reporting.

So, let's look at another sort of classic metric that we tend to kind of look at from time to time, which is the number of requests. You know how they say in a classic sort of like modus operandi, the quickest request is the one that's never made. All right, I think that's fair. So, if we kind of extrapolate for digital sustainability, the greenest request is the one that's never made. What does that mean? Well, if you're not going to send the request down, chances are you don't need that request and you're almost assuredly making your way towards a greener site with less carbon footprint and eventually less emissions.

But let's look at some data about requests. At the 75th percentile, we are seeing 37 requests for JavaScript alone. Alright, at the 75th percentile, 37 requests just for JavaScript. At the 90th percentile, we are seeing 62% more requests on its own. Now, if we go back a couple, and again, think of the amount of unused JavaScript that we are sending down the wire, we can start to do the math, and there are probably a lot of wasteful requests right there. These things that you want to test, you want to look at, and see where you can make some improvements.

So we've just looked at some classic page weight data. And all it was, really, is painting the idea that there's a lot of JavaScript resources coming down the wire. You might think to yourself, like, I don't know, what's this all about Ong? Like why are we talking about page weight regarding JavaScript around a sustainability conversation? Well, I'll tell you right now. It starts with things like this, the greening of the government. Well, this is a piece that was released by the UK government. And they're basically saying that they are taking steps towards being much more or taking steps towards having sustainability as a priority one, especially making sure that they are digitally sustainable as well. Here's a quote that I really like, Business as usual is no longer an option. It is, therefore, vital that HMG, which I believe is her majesty's, her anyways, digital services and ICT are responsible and resilient, her majesty's government. There we go. Pardon me, I was blanking out. So right there you can see they are announcing openly that they are making sure that they are going to be practicing the best sustainability measures possible. Now further in that same document, you'll actually see that they talk about partnering with businesses that have sustainability in mind, who are open with their plans and that means that essentially they are going to partner with people who are like-minded. So if you're not keeping sustainability or digital sustainability in mind, the government may not be one of your clients. These are the kinds of things that we want you to think about. Now something else that I want to talk about is the European Union is also following in these kinds of footsteps. In fact, if you look up this document called the Corporate Sustainability Reporting Directive, the European Union is saying the following, the new rules will ensure that investors and other stakeholders have access to the information they need to assess investment risks arising for climate change and other sustainability issues. So once again, you have another large organization that is essentially saying the following, sustainability is going to be a priority for us. And in their case, starting in 2024, details pending, but it sounds like organizations that are large, or that are 250 persons and larger, will be mandated to make some sustainability or provide some sustainability reporting so they can see exactly what they're doing. These are things that you should talk about, or at least you should think about, and we've been thinking about as well over at Catchpoint.

6. Introducing the Carbon Control

Short description:

We've released something called the carbon control, which provides an estimate of your carbon footprint alongside performance data. It shows page performance metrics and an experimental estimate of your carbon footprint. The carbon control summary includes information on green hosts, third party domains operating on renewable energy, and an estimated carbon footprint. We use the GreenWeb Foundation's CO2GS library and GreenWeb dataset for domain checks. You can visit webpagesets.org/carbon-control to get an estimate of your carbon footprint and explore additional features. Page weight and carbon footprint are closely tied, and we believe they should be considered together for digital sustainability. Thank you for listening, and feel free to reach out with any questions or comments.

And in fact, what has happened is that we were discussing the idea of potentially providing some kind of sustainability metric or maybe a carbon footprint metric or estimate alongside our performance data. And essentially we decided to do that. So I'd like to sort of like introduce you to something we've released called the carbon control. And what that is is essentially an estimate of your carbon footprint that we provide when you do a performance audit.

Now it's going to look a little something like this in fact, you're going to get, you're going to drop in your URL, hit go, and you're going to get your classic performance summary just like you see right there. So what do you see is the page performance metrics. So TTFP, some of the paint metrics that I was talking about earlier. But on the far right you can see we're providing in an estimate of your carbon footprint. We're calling it a bit of an experimental kind of like a canary.

So if you look at the actual carbon control summary, it looks a little something like this. So first we're going to tell you whether or not you're using a green host, meaning is your host operating on renewable energy. We're also going to look at the same data for your third party domains. Are they operating off renewable energy? And we'll give you sort of like, not so much a score, but we'll let you know which ones are and which ones are not. And then ultimately we'll show you the estimated carbon footprint with the page weight and what we sort of calculated as likely a decent estimate of your footprint right there. Now I want to give a shout out to the GreenWeb Foundation because we're actually using the library's CO2GS and also their GreenWeb dataset for the domain checks. So you know, if you were at all curious to take a look at that you could actually go to webpagesets.org slash carbon dash control. It's totally free. You don't even have to sign up, although we recommend you do because you actually can take advantage of some additional features. But this is where you'll be able to see and kind of like get an estimate of your carbon footprint alongside some of these performance metrics. And why do we feel that they belong together? Well, essentially, they're kind of close tied because if you're going to talk about page weight information and carbon footprint and emissions and you can sort of see that the more page weight you have, the greater the emissions obviously, well, they really should live under the same roof. And that's essentially why we felt that A, they belong together. And B, like I said, we've been looking at some of this guidance that was coming out in terms of like sustainability and businesses that were starting to not so much demand, but recommend being digitally sustainable. And we just felt that this was metrics that belong, like I said, together under the same roof. That being said, ultimately, it's also good for the environment. So what I would like to do in, in, in wrapping up is saying, thank you very much for listening. If you have any questions about what you've heard today, please definitely let me know. Shoot me a little tweet or whatever, at Henri Albertca, I'd be glad to answer your questions. Otherwise, I look forward to hearing from you.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
JSNation 2023JSNation 2023
26 min
When Optimizations Backfire
Ever loaded a font from the Google Fonts CDN? Or added the loading=lazy attribute onto an image? These optimizations are recommended all over the web – but, sometimes, they make your app not faster but slower.
In this talk, Ivan will show when some common performance optimizations backfire – and what we need to do to avoid that.

Workshops on related topic

React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Featured WorkshopFree
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
WorkshopFree
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Vue.js London 2023Vue.js London 2023
49 min
Maximize App Performance by Optimizing Web Fonts
WorkshopFree
You've just landed on a web page and you try to click a certain element, but just before you do, an ad loads on top of it and you end up clicking that thing instead.
That…that’s a layout shift. Everyone, developers and users alike, know that layout shifts are bad. And the later they happen, the more disruptive they are to users. In this workshop we're going to look into how web fonts cause layout shifts and explore a few strategies of loading web fonts without causing big layout shifts.
Table of Contents:What’s CLS and how it’s calculated?How fonts can cause CLS?Font loading strategies for minimizing CLSRecap and conclusion
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Next.js is a compelling framework that makes many tasks effortless by providing many out-of-the-box solutions. But as soon as our app needs to scale, it is essential to maintain high performance without compromising maintenance and server costs. In this workshop, we will see how to analyze Next.js performances, resources usage, how to scale it, and how to make the right decisions while writing the application architecture.