Content Delivery Networks (CDNs) have revolutionized web hosting during the past few years. Rather than hosting your website a single server, you can distribute the files and load across multiple systems.
Most CDNs are used to host static resources such as images, videos, audio clips, CSS files and JavaScript. You’ll find common JavaScript libraries, HTML5 shims, CSS resets, fonts and other assets available on a variety of public and private CDN systems.
There are a number of free CDNs offered by Google, Microsoft, Yahoo and other large web organizations. For example, few people host their own videos when YouTube and Vimeo offer amazing free services. Similarly, if you require jQuery, you can load it on any page using:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js.js"></script>
or
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js"></script>
Alternatively, you could use a private commercial CDNs such as Amazon S3, Microsoft Windows Azureand MaxCDN to host your own files.
There are several reasons why a CDN could benefit your website and company.
1. Different domains
Browsers limit the number of concurrent connections (file downloads) to a single domain. Most permit four active connections so the fifth download is blocked until one of the previous files has been fully retrieved. You can often see this limit in action when downloading many large files from the same site.
CDN files are hosted on a different domain. In effect, a single CDN permits the browser to download a further four files at the same time.
2. Files may be pre-cached
jQuery is ubiquitous on the web. There’s a high probability that someone visiting your pages has already visited a site using the Google CDN. Therefore, the file has already been cached by your browser and won’t need to be downloaded again.
3. High-capacity infrastructures
You may have great hosting but I bet it doesn’t have the capacity or scalability offered by Google, Microsoft or Yahoo. The better CDNs offer higher availability, lower network latency and lower packet loss.
4. Distributed data centers
If your main web server is based in Dallas, users from Europe or Asia must make a number of trans-continental electronic hops when they access your files. Many CDNs provide localized data centers which are closer to the user and result in faster downloads.
5. Built-in version control
It’s usually possible to link to a specific version of a CSS file or JavaScript library. You can often request the “latest” version if required.
6. Usage analytics
Many commercial CDNs provide file usage reports since they generally charge per byte. Those reports can supplement your own website analytics and, in some cases, may offer a better impression of video views and downloads.
7. Boosts performance and saves money
A CDN can distribute the load, save bandwidth, boost performance and reduce your existing hosting costs — often for free.
As you’d expect, that’s not the whole story. Come back soon for 7 Reasons NOT to use a Content Delivery Network…
1. Additional complexity
A link to a CDN file won’t work if you’re developing offline. That’s rarely an issue, but some developers have temperamental internet connections or need to work on the move.
You also likely to require a build process or manual intervention when deploying your site to a live server. It will be necessary to CDN-ize local links to JavaScript libraries and other assets. It could become complicated if you’re using a service such as Amazon S3 to host some resources but not others.
2. Files may not be optimized
Consider a modular library such as Modernizr or YUI. Free CDN-hosted files are available but they generally provide all the common functionality within a large package that may exceed several hundred Kb.
If you just require a few features, you can use your own specialized versions and merge all CSS and JavaScript files to invoke fewer HTTP requests. The result is smaller files which download quicker and execute faster — especially on mobile devices.
That said, you could upload optimized files to a private CDN but you would need to consider the additional effort and cost that would incur.
3. There are no pre-caching guarantees
While there’s a higher probability a popular CDN file has been pre-cached, it’s not a given. In particular, mobile devices tend to have small and fairly inefficient caches. The advantages may be negligible, especially if you can host a smaller file on your local server.
4. Blocked access
We live in a world with geographic, legal, political, and commercial boundaries. It’s not uncommon for organizations or whole countries to block the domains or IP address of popular free CDN services.
Similarly, companies such as Google and Microsoft must adhere with US export laws. There are known restrictions on use of data in Cuba, Iran, North Korea, Sudan and Syria. The list of blocked countries can change on the whim of any government.
5. Two points of failure
It’s catastrophic when your site goes down and, despite a good reliability record, CDNs aren’t infallible. There’s little you can do but wait for the service to resume.
It would be possible to use a CDN and fall-back to local files if the service isn’t available. It’s a solution which provides a good level of redundancy — at the expense of further development and complexity.
6. Security
If security is a major concern, don’t use a public CDN. When a remote file is called, information about the referrer is also sent. Remotely-hosted JavaScript libraries are particularly risky since the code could be modified to collect data about your users or systems.
Similarly, your CDN options will be more limited if you require HTTPS.
7. Loss of control
Are you happy handing control of website files to Google, Microsoft, Amazon or any other large web company? Are you concerned they’re collating information about your website and systems? Do those companies have too much control over the net? Perhaps it’s paranoia, but you have a reason to be paranoid when everyone’s out to exploit you!
原文:http://www.cnblogs.com/abapscript/p/4851931.html