Blog Home RSS Kelvin Jackson

Use Less JS (It's Good For The Environment!)


The less JavaScript (and fewer frameworks) you include in your website, the less harmful it is for the environment. After all, every time you execute code or download resources, that takes energy — and caching only goes so far. Computers consume a lot of electricity, and that usage will only increase.

Even without trying to quantify how much energy is wasted downloading JavaScript, it is clear that some sites would do just fine without it. No static page containing only infrequently-updated text needs scripts — and this covers a wider range of sites than you might think at first. The environmental impact of your site is just one more reason among many to always ask whether you really need JavaScript, or whether you really need React, etc.

Less code will usually also mean less effort spent maintaining the app later on. This principle can certainly be taken to an unhealthy extreme, and create even more work later, but most of the time leaving out truly unnecessary dependencies is a win for the maintainer — on top of reducing the amount of data transfered every time the site is loaded. You can then use the time you saved to make other apps more efficient.

Now, if you really want to write efficient code, you have to go back to writing native apps again and ditch the browser-as-OS trend that has sprung up in recent years. However, you would be fighting an uphill battle against an industry that values portability over efficiency and speed — sometimes for good reason, although often in vain. In 2022, it might be better to work with what you have.