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. It is perfect time to make some plans for the future and it is time to be happy.
    I’ve read this post and if I could I wish to suggest you few
    interesting things or tips. Perhaps you could write next articles referring to this article.
    I wish to read even more things about it!

  2. For newest news you have to pay a visit world wide web and
    on world-wide-web I found this website as a
    most excellent website for most recent updates.

  3. My family members all the time say that I am wasting my time here at
    net, except I know I am getting knowledge everyday by reading thes good articles or reviews.

  4. I like the valuable information you provide in your articles.

    I’ll bookmark your weblog and check again here frequently.
    I am quite certain I’ll learn lots of new stuff right here!

    Good luck for the next!

  5. Its like you read my mind! You appear to know a lot about this,
    like you wrote the book in it or something.

    I think that you can do with a few pics to drive the message home a little bit,
    but instead of that, this is fantastic blog. A fantastic read.
    I will definitely be back.

  6. of course like your web site however you have to test the spelling on quite a few of your posts.
    Several of them are rife with spelling issues and I
    find it very troublesome to inform the reality however I’ll surely come again again.

  7. I have to thank you for the efforts you’ve put in penning this website.

    I am hoping to view the same high-grade blog posts by you in the future as well.
    In truth, your creative writing abilities has encouraged me to get my own, personal site now ;)

  8. Thanks in favor of sharing such a nice idea, paragraph
    is nice, thats why i have read it fully

  9. Have you ever thought about including a little bit
    more than just your articles? I mean, what you say is important and all.

    But think about if you added some great graphics or video
    clips to give your posts more, “pop”! Your content is excellent but with images
    and videos, this site could undeniably be one of the very best in its
    niche. Wonderful blog!

  10. Having get right of entry to distinct elements adapted certainly toward improving social/emotional construction proves valuable throughout varied backgrounds encountered every single day!!! ### anyKeyWord### infant child care

  11. hello there and thank you for your information –
    I’ve certainly picked up something new from right
    here. I did however expertise a few technical issues using this site, since I
    experienced to reload the site lots of times previous to I could get it to
    load properly. I had been wondering if your web host is OK?
    Not that I am complaining, but sluggish loading instances times will often affect your placement in google and can damage your quality
    score if ads and marketing with Adwords. Anyway I am adding this RSS to my e-mail and can look out for a lot more of your respective exciting content.
    Ensure that you update this again soon.