Accelerating your website & reduce load – CloudFront


Cloudfront is the AWS content distribution network (CDN) which uses edge locations all across the globe to serve your content to your users from a location that’s geographically close to them – reducing latency and improving load times.

It does this by caching your content on the edge locations. However, it only caches the content after it’s been requested by a user. So, let’s say user 1 requests an image from your website. Cloudfront will not have cached this image yet, so it’ll have to go back to the origin (your S3 bucket) and pull it back for the user. This image will then be cached for user 2, so it will not need to hit the origin.

This can be problematic if you have an edge location from which you serve very few customers. For example, if you run a company in London & most of your clients are from Europe, you may find that those customers in America don’t visit your website enough to cache your resources & they may experience slower load times as Cloudfront must request resources from the origin for every request. To counter this issue, you can remove certain edge locations from Cloudfront & re-route the users in America to use the European edge locations.

When you cache an object and want to update that object, you can either re-upload it with a different name or you can invalidate the object in the cache (which does incur a charge) – forcing it to upload the new version.

Performance of Cloudfront can be affected by filesize, file type, slow DNS lookups and query strings on websites (as each query is likely to be unique and therefore the results are less likely to be cached).

You can configure cached items to timeout after a certain period. Longer cache timeouts improve performance.