jQuery CDN as A Named Module In RequireJS

If you want RequireJS to fetch jQuery from a CDN, you’ll need to tell it to do so using the “paths” config:

require.config({
paths: {
"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"
}
});

As I understand it, if you want to use the local file fallback code a la html5bp you’re out of luck. For those of you who don’t know, the local file fallback code allows you to load jQuery from your own domain if the CDN version fails to load. It looks like this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.2.min.js"><\/script>')</script>

Arguably, if you’re using jQuery it is likely to be a global requirement rather than a requirement for one or two modules. The same sort of thing with BackboneJS. It might be better to place these global requirements in the HTML for your pages (before the RequireJS script) to save typing ‘jquery’ and ‘backbone’ in all your module definitions.

22,429 thoughts on “jQuery CDN as A Named Module In RequireJS

  1. Thank you, I have just been looking for info approximately this
    topic for a while and yours is the greatest I’ve came
    upon so far. However, what about the bottom line? Are you certain about the supply?

  2. Hmm is anyone else having problems with the images on this blog loading?

    I’m trying to determine if its a problem on my end
    or if it’s the blog. Any feedback would be greatly
    appreciated.

  3. What’s up mates, how is the whole thing, and what
    you want to say regarding this article, in my view its genuinely awesome for me.

  4. Way cool! Some very valid points! I appreciate you writing this post
    plus the rest of the website is extremely
    good.
    Esthetic Dental Clinic – DENTYSTA Toruń – Stomatologia
    estetyczna – Implanty – ORTODONTA TORUŃ
    Heleny Piskorskiej 15, 87-100 Toruń
    2MG9+W8 Toruń
    edclinic.pl

  5. I was recommended this blog by my cousin. I’m
    not sure whether this post is written by him as no one else know such
    detailed about my difficulty. You’re amazing! Thanks!

  6. Thanks for your personal marvelous posting! I really enjoyed
    reading it, you may be a great author. I will ensure that I bookmark
    your blog and will come back at some point. I want to encourage
    you to continue your great writing, have a nice evening!

  7. សូមស្វាគមន៍មកកាន់ E28BET កម្ពុជា – វេទិការលេងល្បែងដែលផ្តោតលើភាពយុត្តិធម៌ និងការបង់ប្រាក់រហ័សពេញលេញ។
    រីករាយជាមួយបូណាសទាក់ទាញ ហ្គេមគ្រប់ប្រភេទ និងបទពិសោធន៍ភ្នាល់សុវត្ថិភាពងាយស្រួល។ ចុះឈ្មោះឥឡូវនេះ!

  8. Nice article, I have been searching for personalized necklaces.

    I recently found this shop and they have cool name chains that are pretty affordable.

    Worth a look if you like custom jewelry.