A common misconception users make when implementing a CDN is their site will be higher performing, just by using a CDN. That’s not actually true — a CDN can actually result in worse performance and increased latency.
First lets quickly go over how a pull CDN, the method CDN.net uses, works. Your files are hosted on a server somewhere; this is called your origin location. Your origin location is typically just a single server. If you’re not using a CDN, users will download the file from that single server, no matter how far they are from it, or how many others are also downloading from it.
When you use a CDN, your CDN service will download your files and temporarily store them on the CDN PoPs, to serve to your visitors. When the files are temporarily stored, this is referred to as being cached.
What does it mean if the file is not cached? This actually results in poorer performance for your website, as the CDN PoP will need to download the file from your origin location and then serve it to your visitor. This is why cache hit percentage is extremely vital for a high performance website.
Lets go over how we can improve your CDN cache hit percentage.
1.) New files are not cached by our PoPs as they’re uploaded. You can have your files cached on demand using our prefetch utility in the CDN.net control panel.
2.) Purge wisely! If you use the purge utility to purge your content from the CDN PoPs, all your content will be removed from the cache. If you update a single file, you’re able to purge that one single file using the purge utility. Don’t unnecessarily purge your entire site.
3.) Query strings can result in unique file names for each individual visitor. This means that each new visitor will require the CDN to go back to the origin to fetch the file, due to a simple query string.
4.) No cache headers. Our CDN will follow the caching instructions set by the origin. If the headers say “no-cache” or have a short TTL (time to live), you will have a poorer cache hit rate. For static files that do not change, you can set a long TTL period, ensuring a higher cache hit rate.
How do you know if your files are cached? You can check this by running a simple script in terminal, and checking the return for X-Cache. A return of “HIT” means that the file is cached on the CDN, while “MISS” would mean the file is not cached on the CDN.
tmyers$ curl -i https://i.cdn.net/wp-content/plugins/column-shortcodes/assets/css/shortcodes.css
HTTP/1.1 200 OK
Date: Tue, 11 Apr 2017 13:20:38 GMT
Content-Type: text/css; charset=utf-8
Last-Modified: Tue, 21 Mar 2017 16:43:54 GMT
Expires: Tue, 10 Apr 2018 08:23:24 GMT
Following these tips will help improve the cache hit rate, thereby dramatically increasing the performance your website and taking full advantage your CDN’s capabilities. If you’re a CDN.net user, we’re continuously monitoring the cache status, to allow for the greatest hit rate possible. We do this by increasing the number of servers, and cache capacity as necessary. If you’re still struggling with poor website performance, and a low cache hit rate after implementing these steps, just reach out to us. We’re happy to help.