Now, its time to improve response time. This can be done by adding cache layer and shifting static content to CDN.
A CDN network used to deliver static content like images, videos, CSS, JavaScript files etc.
When a user visits a website, a CDN server closest to the user will deliver static content. Basically, further users are from CDN servers, the slower the website loads.

User A tries to get image.png by using an image URL. The URL’s domain is provided by the CDN provider. If CDN server does not have image.png in the cache, the CDN server requests the file from the origin, which can be a web server or online storage like Amazon S3.
The origin returns image.png to the CDN server, which includes optional HTTP header Time-To-Live (TTL) which describes how long the image is cached. The CDN caches the image and returns it to user A. the image remains cached in the CDN until the TTL expires. User B sends a request to get the same image. The image is returned from the cache as long as the TTL has not expired.
Considerations of using CDN:
- Cost: CDNs are run by third party providers and you are charged for data transfer in and out of the CDN.
- Setting an appropriate cache expiry: The cache expiry time should neither be too long or too short. If it is too long, the content might no longer be fresh. If it is too short, it can cause repeat reloading of content from origin servers to CDN.
- CDN Fallback: You should consider how your application cope with CDN failure. If there is temporary CDN outage, client should be able to detect problem and request resource from origin.
- Invalidating Files: You can remove a file from CDN before it expires by performing one of the following operations:
- Invalidate CDN object using APIs provided by CDN vendors.
- Use object versioning to serve a different version of the object.
Benefits of using CDN:
- Improving website load times
- Reducing bandwidth costs
- Increasing content availability and redudancy
- Website Security
CDN can reduce amount of data that is transferred by reducing file sizes using tactics such as minification and file compression. Smaller file sizes mean quicker load times.
CDN can keep a site secured with fresh TLS/SSL certificates which will ensure high standard of authentication, encryption and integrity.


Leave a comment