Host jQuery at Google (with Intellisense support)

tp_vol3_007 While reviewing my RSS feed this morning, I found this article:

3 reasons why you should let Google host jQuery for you | Encosia

I had no idea!

The three reasons are:

  1. Decreased Latency
    Google will serve the data from the closest server
  2. Increased Parallelism
    More threads are available to download content specific to your application instead of downloading this common library.
  3. Better caching
    They may already have the library on their computer.

Here is the code you should be using to include jQuery in your application to use the Content Delivery Network at Google:

    <script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">
    </script>

The one issue you may have to deal with is that if you are using the intellisense files for Visual Studio, you will need to find some alternate method.  Here’s one:

First, place the reference to your local jquery files like we’ve been doing:

<script src="js/jquery-1.2.6.min.js"
  type="text/javascript"></script>

But then in the onload event, put in code to replace the src attribute so that it will get the js file from google:

protected void Page_Load(object sender, EventArgs e)
{
 foreach (Control c in Page.Header.Controls)
 {
  if (c.GetType() == typeof(LiteralControl))
   ((LiteralControl)c).Text =
    ((LiteralControl)c).Text.Replace(
    "src=\"js/jquery-1.2.6.min.js\"",
    "src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js\"");
 }

}

This code might be optimized a bit better.  For example, by making sure the js reference is the first element in your header, you could skip the foreach loop and just grab the first element out of the controls collection.

 

Other post in jQuery

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • Intellisense Everywhere in VB 9 (and a small bug)Intellisense Everywhere in VB 9 (and a small bug) One of the features the CSharp guys have had for quite a while is Intellisense everywhere.  Want to create a private variable?  Just start typing private and hit the tab key as soon as the […]
  • Getting started with jQuery and ASP.NETGetting started with jQuery and ASP.NET As promised, I am starting a series on jQuery.  Today our goal is to get a project setup in Visual Studio that uses jQuery.  We won't be explaining much in the way of syntax, but we will […]
  • jQuery GUI – DragjQuery GUI – Drag About a year and a half ago I helped develop an application that required drag and drop functionality.  We used the MS-AJAX framework to implement it at the time because it was available […]
  • jQuery – Creating Plug-insjQuery – Creating Plug-ins Last week we looked at how to have jQuery execute our own functions. I suggested at the time that if you were going to need to use that function in multiple applications, you might want […]
  • Overriding Events in VB.NETOverriding Events in VB.NET Back in the day, you use to be able to override an event in VB by using the drop down list in the code window.  Today, I had a friend who is moving from Visual Studio 2003 to Visual […]

About Dave Bush

Dave Bush is a .NET programmer and Certified ScrumMaster who is passionate about managing risk as it relates to developing software. When he is not writing or speaking about topics related to Application Lifecycle Risk Management (ALRM), he is an example to his peers as he develops web sites in the ASP.NET environment using industry best practices.

One Pingback/Trackback