19 Aug 2021
- Comments (1)
Use self-hosted files instead of using CDN.
In today's age we are using CDN to speed up loading times for our visitors, but is it the right sustainable thing to do?
Most web developers today choose to host files and load them through a CDN since it in most cases is faster than hosting it on your server. Hosting files on a CDN will ensure that the files are fetched from the closest location to the visitor instead of the location of the website server. To give you an example: If the website receives a visitor from Australia and the server is located in Frankfurt, then it would take a longer time to load the resources from Frankfurt than it would do to load it from a CDN located in for example Indonesia. The reason for that is the shorter route from point A to B.
Loading files through a CDN is smart and since we for many years have focused on loading times, it has been the best option available for developers to provide fast loading websites. But if we turn the table and look at the environmental impact it has, can we then also conclude that loading files through a CDN are the best sustainable option we have? Or should we change our behavior and adopt a more sustainable way of fetching files for our projects? In this article we will dive into the effect it has loading files through a CDN compared to the effect of hosting the files on our server.
Fetching files using a CDN.
When fetching files through a CDN we will be sending a request to a hosting server where the file or files are located. The hosting server will then send the requested file or files to you from their nearest location to minimize traveling distance and time. This method is really good if you want to lower the overall loading times for visitors, but in the sustainable and green perspective, it is different.
You see, fetching files from a CDN causes one or multiple servers around the world to spin up and use electricity to send you the requested files. Already when the user decided to visit your website they caused your server to use electricity, but if your website also requires other servers to use electricity it will become a chain reaction. Of cause, the CDN may be running entirely on sustainable green energy, but chances also are that it doesn’t. We possibly cannot know for sure unless we were to investigate the individual CDN and all of their locations.
Visiting a website hosted by coal energy could easily cause between > 0,60g CO2 pr visit. If you on top of that are using one or two CDN sources then you potentially add > 0,60g CO2 on top of the CO2 you already caused. In one or two visits the numbers might not be high, but let's say you have approximately 10.000 visitors a year then you would emit around or more than 12kg CO2 just for a standard website.
Services such as Netflix, Disney plus and other streaming websites not using green sustainable energy will cause an even higher number due to the amount of data needed to be transferred.
When knowing these numbers, then imagine there are billions of websites around the world. As you see, every website counts and we all need to be doing something to help to remove the issue.
Self-hosting files on your server.
Back in the days before CDN’s were invented, we were hosting all files on our servers. The option of self-hosting is old, but the idea of it might become relevant once again now that we open up and talk about the issue of CDN’s using electricity and the uncertainty of them using green sustainable energy. To picture it out: Let’s say you started a grill in your backyard. If you host all of your files on your server, it would be like throwing coal onto your grill, but when you fetch files through a CDN you would be throwing coal on your grill and also over the hedge to your neighbor's grill. You don’t know your neighbor's grill, but you keep making it burn, and therefore you could be causing damages without even knowing.
If you are looking to build and host a more sustainable website and if you already use a server or servers only running on green sustainable energy, then we recommend hosting files such as fonts, style sheets, and scripts on your website server instead of using a CDN. Doing so will help to lower the impact every specific visit has on your website and thereby helping to lower the overall problem of the internet being one of the most polluting inventions today.