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. example-hexid.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
.css
,.js
,.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://www.keycdn.com/img/example.jpg
This should return a response similar to:
HTTP/2 200 server: keycdn-engine date: Wed, 15 Jun 2022 06:43:47 GMT content-type: image/jpeg content-length: 195025 last-modified: Thu, 16 Jul 2020 07:06:27 GMT vary: Accept-Encoding etag: "5f0ffc73-2f9d1" expires: Wed, 22 Jun 2022 06:43:47 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 x-cache: HIT x-edge-location: chzh access-control-allow-origin: * accept-ranges: bytes
Run a site speed test and verify the
X-Cache
response 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.
Summary
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.