tags:

views:

100

answers:

2

I've built a javascript file that my clients will be installing on their website which will call my server. I'm wondering if it would be better to host the javascript file on a CDN, instead of on my server? The benefits would be better response time and a much higher chance that it will always be available. However, In the future, if the CDN was bought by another company or went out of business the file may no longer be accessible and I would have a number of clients linking to a file that doesn't exist. Is there any way to prevent this from happening?

A: 

CDN's don't always speed things up. Unless the CDN is very popular, the browser won't have the script cached. It will have to perform another DNS lookup and create a new connection which takes some time.

The CDN being more reliable is also a false benefit because if your site is down it doesn't really matter that the CDN is up.

It might save you some bandwidth though but only a small amount. jQuery for example is a lot smaller than the background image used by jquery14.com

meouw
Really the main benefit to me is that if my server goes down, the websites that are linking to my javascript file will not be effected if the file is in a CDN. However, if the file is on my server and it goes down, my clients websites may not fully load because the request will timeout (depending what browser the user is using).
mike
DNS lookups are also cached. It will mostly be a one-time hit when first visiting the site.Even with this hit, page load times can be smaller due to parallelized downloads: http://code.google.com/speed/page-speed/docs/rtt.html#ParallelizeDownloadsjQuery might be small, but serving it to 200.000 unique users is 4.5GByte/day. Why not save and at the same time make your site faster?Also, one of the CDNs for it is google. I believe that counts as popular.
andras
+2  A: 

To Reference a content from CDN, you can either point your domain / subdomain to CDN servers and clients can reference the JS using your domain. So in future if you would like to switch the CDN, its just DNS entry away.

If you are not intrested in buying up space in a CDN, then you should suggest your clients to host it in a domain / subdomain which they own and update the DNS records to point to the CDN of their choice.

Ramesh
Does this mean I could setup a new A record in my DNS settings for 'script' and have this forward to aCDN? Or, do I need to setup the subdomain in apache on my server and do a modrewrite to the CDN server?
mike
@yummm: The CDN you choose will probably provide you with more instructions. (They will presumably recommend setting up a CNAME record.)
andras
This is exactly what I needed. Thanks so much!
mike