I like this for quick prototyping tests on code that uses resources such as Jquery and Bootstrap because I can do a test in one file.
In production, it may be better to host Bootstrap and Jquery yourself. You have more control over them and the performance may be better, but that all depends on the CDN.
How to use Bootstrap with a CDN
It’s easy to use Bootstrap with a CDN.
1. Instead of using a local file reference, just include an href to the stylesheet somewhere between the
<!-- Obtain Bootstrap style sheet from CDN (online service) so it doesn't have to be on my machine -->
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
2. Link to the CDNs for Jquery and Bootstrap between the
<!-- Obtain latest version of jquery automatically from online server so it doesn't have to be on my machine -->
Here’s everything you need to put up a Bootstrap site, all in a single file. Simply copy and paste into a file called index.html or whatever you wish to name it. It will work fine on your own machine or on a server, unchanged. And you don’t have to remember to create Bootstrap or JQuery directories.
An error has occurred. Please try again later.
The site will look like this:
How I found the Bootstrap CDN
If you want to know whether a library you’re interested in is available on a CDN somewhere, just search for bootstrap cdn or whtaever. That’s how I found bootstrapcdn.com
Advantages to using a CDN
- Someone else maintains these files for you and often can automatically upgrade to the latest version
Disadvantages to using a CDN
- If the CDN goes out of business, you have to re-host on your own website
- If the CDN performance is bad, it reflects badly on your website
- If you use something like jquery_latest (shown below) to obtain the most recent version, it’s possible that new, incompatible code in the library may break your existing code.
- It doesn’t work offline, so you can’t develop without a net connection.
- It’s easy to forget to upgrade a library if versions change. The JQuery CDN avoids this neatly by using jquery-latest.js