Check If CDN Is Working
Learning how to check if your CDN is properly installed and working can save you time and reassure you that the integration process was successful. Doing so is a straightforward process and doesn’t take much in terms of tools or time. This guide will cover the ways and steps needed to properly check if CDN is working for your particular application.
Integrating your application with a CDN
Before verifying that your CDN is properly set up, first double check your CMS or Framework’s CDN integration guide. If you’re integrating your application with KeyCDN, we have a variety of guides available which outline the process step by step:
Checking if your CDN is integrated
Once you’ve carefully followed each step of the integration process for your CMS or framework, you should check if the CDN has been properly integrated with your site. There are a few ways to do this. First of all, take note of which URL you used during the integration process, was it the default Zone URL (e.g.
lorem-1c6b.kxcdn.com) or did you configure a Zone Alias (e.g.
cdn.yourwebsite.com). This is important as this URL is what you will need to look for in the methods below.
- The first method to check if your CDN is integrated with your site is to run a site speed test. Choose any location to run it from and then analyze the URLs of your site’s static assets. Are these URLs showing the CDN URL you defined during the integration process or are they your origin URL? If your static assets are still being delivered from your origin URL you’ll need to double check the integration guide and ensure you’ve followed each step.
- The second way to check if your CDN is integrated is by inspecting the page source of your site. In Chrome, simply right-click on your page and select “View Page Source”. This will open another window displaying all of your site’s HTML.
From here, browse through the HTML and look for signs of static assets (e.g. ending with
.png, etc) If the URL used to deliver those assets is the CDN URL you defined during the integration process you’ve successfully integrated a CDN with your application.
Checking if your CDN is caching content
Once you’ve confirmed that the CDN is properly integrated into your site, you’ll want to ensure that it is delivering cached content as expected. In certain cases (such as when there is no
Content-Length header present) the CDN won’t properly cache your content, resulting in an
X-Cache: MISS. Although the CDN will be integrated, it won’t help improve your speed if this is the case.
To ensure your CDN is caching content you should check the HTTP headers of one of your static assets to ensure it is returning a
HIT response. In the case of KeyCDN, we define this with the
X-Cache header as mentioned above. To ensure the CDN is returning a
HIT response, you may need to reload the content a few times. To verify this, use one of the methods below:
Perform a curl command on one of your assets, for example:
curl -I https://cdn.keycdn.com/img/cdn-stats.png
This should return a response similar to:
HTTP/1.1 200 OK Server: keycdn-engine Date: Fri, 23 Mar 2018 17:00:16 GMT Content-Type: image/png Content-Length: 177797 Connection: keep-alive Last-Modified: Mon, 26 Sep 2016 12:15:43 GMT ETag: "57e9116f-2b685" Expires: Fri, 30 Mar 2018 17:00:16 GMT Cache-Control: max-age=604800 Strict-Transport-Security: max-age=31536000; includeSubdomains; preload Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' https: data: X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Referrer-Policy: no-referrer-when-downgrade Link: <https://www.keycdn.com/img/cdn-stats.png>; rel="canonical" X-Cache: HIT X-Edge-Location: camo Access-Control-Allow-Origin: * Accept-Ranges: bytes
Run a site speed test and verify the
X-Cacheresponse header (you may need to run this 2-3 times):
Regardless of the method you choose above, be sure to run the curl command or site speed test a few times so that the edge server can properly cache and deliver the static asset. This is essential, especially said asset has never been requested before since integrating the CDN.
As demonstrated in this article, there are a few different ways to check if a CDN is working. They’re all pretty simple and regardless of which method you choose, you’ll be able to accurately determine whether your CDN is properly integrated or not.