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

Other Related Items:

Studio Indoor/OutdoorStudio Indoor/OutdoorStudio Indoor/Outdoor Marine Wall Light Bronze with seeded glass Hand rubbed Antique glass & Chrome with clear glass Mfg code(s): SLO2001BZ-SG, SLO2001HAB-CG, SLO2001CH-CG
RSVP Tortoise Onion Goggles- Great for Tear Free Chopping,Dicing,Slicing Raw OnionsRSVP Tortoise Onion Goggles- Great for Tear Free Chopping,Dicing,Slicing Raw OnionsThe tear-free solution for slicing, dicing, mincing, and grating raw onions. Anti-fog clear lenses offer maximum clarity while the foam seal protects the eyes from irritating onion vapors. The unisex design will fit most face shapes, but will not fit over glasses. Includes storage case.
Red Baron Motorcycle/aviator Goggles Googles Day NightRed Baron Motorcycle/aviator Goggles Googles Day Night2 Red Baron Style Motorcycle Goggles. You will receive one with Smoked lenses and one with clear lenses. Made by Global Vision

If you're new here, you may want to subscribe to the mailing list to get notifications of new post and a virtual tour of past topics. Thanks for visiting!

Related Post

One Response to “Host jQuery at Google (with Intellisense support)”

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor