How Do I Check That a Content Delivery Network (CDN) is Available?

The #1 way to speed up your website is to minimize HTTP requests, however; inevitably you will make request for images, audio, video, code, and other content. Whenever; you can off load some of the content to other domains or to other servers your site will always load faster. However; there will be times when those ‘other servers’ will be down. Whether it is just for a moment or for a longer period of time, you do not want your site to be at the mercy of those servers. What can you do? (Glad you asked). You can have the best of both worlds. Why not check to see if the ‘other’ server is available. If it is then use their servers to deliver your content. If not then just load your own content from your site. It is not that hard to do and takes about 3 more lines of code. You can use this for anything in particular. Just find the piece of code to check for.

I am giving you this example of the jQuery library and any library will do just replace the code with the syntax for their library.

[sourcecode language=”javascript”]<br />
&lt;script type=&quot;text/javascript&quot; src=&quot;;&gt;&lt;/script&gt;<br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
if (typeof jQuery == ‘undefined’) {<br />
document.write(unescape(&quot;%3Cscript src=’../javascript/jquery-1.6.1.js’ type=’text/javascript’%3E%3C/script%3E&quot;));<br />
}<br />
&lt;/script&gt;<br />

I do not think this needs a lot of explaining but just in case here we go.

Line 1: Load of the library from a CDN (Content Delivery Network).
Line 2-6: Checks to see if the library got loaded. If it did not then inject your library into the page. Then on the load it will then load yours and not the one from the server. This
way you never load it twice but you always use the one from the CDN.

Looking for reliable web hosting? Then look no further than Arvixe!

Tags: , , , , , , , , , , , , , , | Posted under ASP .NET 3.5 | RSS 2.0

Author Spotlight

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *