Page 3 of 3 First 123
  • Jump to page:
    #31
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    26

    Use Google CDN for Javascript libraries


    For the benefit of your users' and your own server's bandwidth, whenever you use a library like prototype, jquery, scriptaculous, or whatever, consider pointing your links to a hosted Content Distribution Network such as Google's. Your users' browsers likely already have these cached, as they are used all over the place.

    For example, instead of pointing to jQuery locally, just point your users to Google's copy:
    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    (See how the src attribute doesn't start with the protocol name? The browser will use the proper protocol, http or https, to match the one in the URL bar.)

    If you're concerned about the CDN's availability, you can back it up with a local copy:
    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>window.jQuery || document.write("<script src='/path/to/your/scripts/jquery-1.10.2.min.js'>\x3C/script>")</script>
    If the client's browser couldn't reach ajax.googleapis.com, the next bit of script will see that no jQuery object has been loaded, and try to download the library from your server.

    For a lot of people this will be uselessly old news. But many posts I've seen on this board since I came back indicate that this information needs to be out there in front of newer web developers.
  2. #32
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Thanks for this wonderful post. Really a great post and very helpful for visitors.!!
  4. #33
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    48
    Rep Power
    0
    thanks to provide this useful information
    Last edited by Kravvitz; September 16th, 2013 at 11:34 PM.
Page 3 of 3 First 123
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo