Reputation: 7332
Kind of self-explanatory question: Why is it recommended loading jQuery or any other library from a CDN?
Upvotes: 5
Views: 464
Reputation: 75317
Upvotes: 9
Reputation: 1831
@Matt hit the nail on the head. In addition to a CDN, you can do a fallback to your local version of jQuery in case the CDN goes down. Example below:
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> -->
<script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>
Upvotes: 5
Reputation: 1900
There are many reasons, but here are a few that stand out:
Many people say that it is risky to rely on the CDN, as what happens if the CDN goes down. This is true, but most likely your site will be more likely to go down that the big guys. That being said, there are approaches that can be used to have a fallback to a version hosted on your site if the CDN does go down.
Upvotes: 3
Reputation: 9759
Two main reasons as far as i know:
1 - It can speed delivery of the hosted files by providing a more proximate route to the client.
2 - It can provide caching benefits for commonly used files since the user may have already downloaded the file from the same cdn
Upvotes: 7