views:

34

answers:

3

It seems like most people use a CDN for placing images and/or videos. Is it wise to place your js and css on a cdn as well?

A: 

I don't think there is anything wrong with it (especially for javascript if you have multiple websites using the same javascript code).

ryanzec
A: 

I believe so. However, if either is dynamically generated you will want to place a relatively low ttl (time to live) on the files so the CDN knows to pull fresh copies. However, if they are not, I would think that dumping them onto Amazon's S3 would be fine.

One caveat - make sure you have an easy way to test and develop without using the CDN as cacheing can be a headache during this process.

Josef Salyer
A: 

While it's a good idea in principle, always have a backup.

With Javascript, if the CDN goes down or the client can't access that js for some reason, then having a local copy as backup will keep your site flexible.

For example, with jQuery, you can have the best of both worlds with this snippet:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
if (typeof jQuery == 'undefined')
    document.write(unescape("%3Cscript src='/scripts/jquery-1.4.2.min.js' type='text/javascript'%3E%3C/script%3E"));
</script>

source and more info

Atømix