DEV Community

Amietubodie Collins Otonye
Amietubodie Collins Otonye

Posted on

How to improve the load and response time of your websites.

Image description

This can be done by done by adding a cache layer and shifting all your static content like javaScript, css, images and video files to the content delivery network which is also known as CDN.

What is Cache ?

Cache helps us to store data so that when we make request for that data later it can be served faster. We can use it store the result of expensive responses or frequently accessed data in memory. Every time you load a web page one or more database calls are executed to fetch data. The application performance is greatly affected by calling the database repeatedly. Cache can help us eliminate this problem.

Cache is a temporary data store and it is more faster than the database. The advantages of using cache is to reduce the workload of the database and to improve the performance of the application.

How does it work ?

When a web server receives a request it first checks if the response exists in the cache if it does it sends the response back to the client. How about if it does not exist? Then it queries the database for the response when it gets the response it saves the response in the cache before sending the response back to the user.

Content Delivery Network(CDN)

CDN servers is used to cache static web content like css, javaScript, images and video files e.t.c. When a user visits a websites a CDN Server closer to the user will deliver all the static contents. if the CDN server are far from the user the slower the website will load. The closer you are to the CDN server the faster you get contents.

How does it work ?

When user A tries to get an image.png if the CDN server does not have image.png in the cache the CDN server request the file from the web server the web server now returns the image to the CDN server which include http headers and TTL which describes how long the image is cached then the CDN caches the image and returns it back to the user. Now if user B wants the same image the image is returned from the cache instead of from the server which a lot faster.

Thanks for reading and God bless us all.

Discussion (0)