Lesson 14To go further, some code practices
- Notion 86 - Introduction to eco web design code practices with The Good Manager project
- Notion 87 - Clean code for energy efficiency
- Notion 88 - Asynchronous code: do more, in less time
- Notion 89 - More efficient and less resource-intensive servers
- Notion 90 - Manage your server workload
- Notion 91 - Using external libraries: the example of Bootstrap CDNs
- Notion 92 - Code practices review
Notion 89
More efficient and less resource-intensive servers
Target skills
Servers delivering content for a website can optimise its files in several ways in order to optimise file size, resource consumption, delivery time, and web page loading. By setting servers correctly, you can therefore reduce its resource consumption. For this, we will have a look at Gzip compression, caching.
Automatic Gzip Compression
By enabling the gzip compression on your server, you could reduce your websites files to a third of their size. The files sent to visitors will be lighter and compressed, hence reduce the website carbon footprint and make the website load faster. The browser of the user will decompress it automatically. It is a must have solution, easy to implement with no downside!
You can enable the gzip option directly from your hosting provider or by modifying the server configuration file (.htaccess). You can learn more about Gzip compression here: https://www.giftofspeed.com/enable-gzip-compression/
Server caching
Caching a file is the action of storing it to avoid further requests for accessing it. By caching a file, you already have it on your disk, and don’t need to ask a server to send it again, therefore reducing the data transferred and loading time.
Cache can be limited in time by setting expirations conditions, and affect different kinds of files. It is configurable directly from your hosting provider or by modifying the server configuration file (.htaccess) once again. Learn more about the caching options for your Apache server here : https://httpd.apache.org/docs/2.4/caching.html
Content Delivery Network
A CDN or Content Delivery Network is a network of servers to deliver web content. It acts as an intermediate before your own server, so requests are sent to this CDN instead of to your main server. It helps mitigate DDos attacks (Attacking an online service in order to make it unavailable) and its localisation can be closer to your visitor than your actual server, which reduces the network load. It has cache and gzip options (see above).