Welcome to the second post of CDN series. In these series, I’m trying to describe how CDN works and with one example show how it can integrate with Episerver and finally we tackle some caching challenges CDN and Episerver has. In this post, we are going to integrate one sample CDN with one of our existing websites. One of CDN Episerver is using in their managed services called DXC is called cloudflare. I have not affiliated with this company and used it because it may be used by some of DXC clients. Cloudflare is quite good and stable service. They have a very simple dashboard and quite good and fast support. So let’s dig down into it!
- I created sample Episerver site and hosted that in http://test5.levo.com.au
- Register on cloudflare – It is free (select free-personal plan) (not CC require)
- Now you need to provide your domain name(s) – my domain name, in this case, would be levo.com – it may take some time to scan domain
- Now you can see list of DNS records which domain scan process fetched. In my case none of them items in the list is relevant, so I removed all of items and add one line for test5:
Cloudflare proposed me to change my Name Server to use Cloudflare which I haven’t. What I did was just is to remove all items and add my “test5” and associated IP address!
- Our original image URL was “http://test5.levo.com.au” so now with our latest cloudflare configuration we can access “test5” using “http://test5.levo.com.au.cdn.cloudflare.net”! So without changing name server, we can test our application. Remember in real world scenario if you need to leverage sage DNS and GEO Loaction DNS, you need to use CDN Domain Name Service!
- Next step is to add record to IIS website binding:
- And obviously new URL to Episerver:
- Navigate to cloudflare URL and you should see CDN version of your site!
- How should I know the site is using the cache?
- In Chome navigate to site using developer tools -> Network
- Wait until all site is loaded
- Find one of your images comes from Episerver:
- You can see “CF-Cache-Status:HIT” in HTTP Header. That means the image is coming from CDN (more information)
- What happens if I delete my asset file from Episerver?
- If you are using CDN URL, CDN will provide the image. That means even if you delete image from your web server, CDN keeps the file till TTL finish (more information)
- How should I know HTML is cached or not in CDN?
- HTTP Header is where to find out:
- As you can see “CF-Cache-Status:HIT” is missing
- If you need want to cache HTML as well you can refer here.
- If I’m going to use CDN, what about if my image or video (or any asset, even HTML of the site) is live and I need to update it?
- This is our next post!
In our next post, we will look into how INVALIDATE CDN cache from Episerver. We are going to build a NuGet package specifically for cloudflare CDN to invalidate cached content when the content is updated in Episerver. This can improve site performance by caching content as much as possible and allow web editors to publish the latest content ALWAYS and finally we plan for integrating visitor group with CloudFalre PageRules! This will be amazing journey, next post will come soon 🙂