Why do I have to test my site twice on GTmetrix to see the speed benefits of cloudflare?

253 views Asked by At

The first test is always slow. The second test shows the speed benefits of Cloudflare. Why is that and does this mean users will have to load the website twice?

1

There are 1 answers

1
Collin Barrett On BEST ANSWER

"speed benefits of Cloudflare" could be referring to a variety of unique features that Cloudflare offers (such as image compression, lazy loading javascript, etc.). For this answer, I am assuming that you are referring to its CDN/caching capabilities.

Essentially, being a CDN means that a client needs to request one of your site's resources from each of the CDN edge nodes to prime the cache at that node from the origin server.

GTmetrix is similar to a human website visitor in the sense that if it is the first to request a resource within its cache timeout from a CDN edge node, the request will have to go all the way back to the origin server rather than responding from the closer edge node. The second time that resource is requested from the edge node, however, the resource will be cached and will be served much quicker due to the reduced network latency.

I'd recommend reading up a bit more on how CDNs work if you are not already familiar with that. You will probably want to tweak your caching headers so that resources that are relatively static are rarely purged from the edge nodes which will reduce requests with this "first-timer penalty".