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?
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
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.