Posted by : Randy Cooper in (CDN)
When choosing to use a CDN there may be numerous ways to integrate your content to deliver it.
Most CDNs employ one of 2 methods for delivering content. The first is origin pull or off-site origin. This evolves the CDN pulling the content from some outside source. This origin could be your webserver, a cloud computing service, something like Amazon S3 or any other internet connected HTTP server. The key is, that the CDN needs to access your content via HTTP GET requests.
The second method is CDN storage. This is storage that the CDN supplies to you on their network. This is usually a preferred method as the CDN does not have to go far to get your content to cache it on edge servers. You can expect to pay for this storage on top of your other CDN charges. Typically, you will FTP the content to the CDN storage or in some cases, there will be an HTTP upload option or even RSYNC may be an option. If your content is large in size, larger than 5-10MB its recommended you store the content on the CDN.
Using CNAMEs to access content
Most CDN’s will use CNAMEs to allow you to access your content. A canonical name or CNAME is simply an alias. For example ‘static.domain.com’ could point to the CDN URL. You can use this instead of the URL that CDN supplies to you. This way you can better brand your site and won’t have the CDN URL floating around on your site somewhere. Talk to your CDN on how to implement a CNAME, they may have special requirements or might not even allow them.
When you do off-site storage, the CDN usually needs to know where you store that content. So be prepared to supply the CDN the CNAME and the Source/Origin URL. Origin, being the URL where the CDN can go to, to pickup your content.
When you write your HTML instead of using a relative path to a file like “./images/logo.jpg” you will use an absolute URL instead, such as “http://static.domain.com/images/logo.jpg”. This way you are essentially embedding content from the CDN on your website.
If you are using a content management system, check to see if there is a way to address all your static elements like images, CSS, java script, PDF, MP3, FLV, MP4, etc at once. You may be able to specify a “pre-pend” URL for specific file types. This would make switching to a CDN easy and quick. You could “CDN enable” your whole site in one click.
How do you know if your content is cacheable?
If you are uploading the content to the CDN then it will be cacheable. If the CDN is going to pull the content from you then you need to consider a few things. Most CDNs will honor any cache control headers you put on your content. For example, if you put a Max-Age=86400 on your content, then the CDN will consider that piece of content fresh for 24 hours. Don’t think for a second you can tell the CDN how long to hold a piece of content in cache for. They will decide when that piece of content needs to be purged from an edge server. However, setting this TTL will tell the CDN that after 24 hours they need to look to see if there is a new version of the file.
Also consider this, if your content has a Private, or No-Cache header on it, then the CDN will probably not cache it, you’re wasting bandwidth. You are trying to deliver non-cacheable content through the CDN, they will go back to your origin for every request.
Some CDNs can address this issue by implementing some custom work around, so talk to your CDN of choice for advice. Also, check with your CDN to see if they require specific cache control headers to be present, you may need to alter your headers in order to make your content cacheable even if you don’t have a No-Cache type header.
This was a basic overview on how CDNs handle basic caching of content from different origins as well as how to deliver your content through the CDN. Consider the issues of cache control headers, these can be very powerful and allow for flexibility on how your content is cached and for how long. You should always work with your CDN of choice directly as they will have specifics for implementing their solution. No 2 CDNs are exactly alike.