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. Hi there to all, how is the whole thing, I think every one is getting more from this website, and your views
    are fastidious designed for new visitors.

  2. Great blog! Is your theme custom made or did you
    download it from somewhere? A design like yours with a few simple adjustements would really make my blog stand out.
    Please let me know where you got your theme. Kudos

  3. I am not sure where you’re getting your information, but good
    topic. I needs to spend some time learning much more or understanding more.
    Thanks for magnificent information I was looking for this info for my mission.

  4. Hey great website! Does running a blog such as
    this require a great deal of work? I have no expertise in computer programming however I had been hoping to start
    my own blog soon. Anyhow, if you have any recommendations or tips for new
    blog owners please share. I understand this is off topic
    nevertheless I just had to ask. Thanks a lot!

  5. I do accept as true with all of the ideas you’ve offered to your post.
    They’re really convincing and can certainly work. Still, the posts
    are too short for newbies. May just you please extend them a bit
    from subsequent time? Thanks for the post.

  6. I’m not sure where you’re getting your information, but good topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for magnificent information I was looking for this info for my mission.

  7. Currently it seems like Movable Type is the best blogging
    platform available right now. (from what
    I’ve read) Is that what you’re using on your blog?

  8. It’s a shame you don’t have a donate button! I’d definitely donate to this brilliant blog!

    I guess for now i’ll settle for book-marking and adding your RSS feed to my
    Google account. I look forward to brand new updates and will share
    this blog with my Facebook group. Talk soon!

  9. Thanks for the marvelous posting! I genuinely enjoyed reading it, you can be a great author.I will ensure that I bookmark your blog and definitely will come back sometime soon. I want to encourage continue your great writing, have a nice evening!

  10. What’s up, I would like to subscribe for this web site to get hottest updates, therefore
    where can i do it please help out.

  11. I was recommended this website through my cousin. I’m not sure whether or not this put up is written by way
    of him as no one else understand such unique about my problem.
    You are incredible! Thank you!

  12. For most up-to-date news you have to visit world wide web and on web I found this web page
    as a best web site for newest updates.

  13. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it
    for you? Plz answer back as I’m looking to design my own blog
    and would like to know where u got this from.
    thanks a lot

    Feel free to surf to my blog … resina de mirra

  14. Greetings from Los angeles! I’m bored to death at work so I
    decided to check out your website on my iphone during lunch break.
    I really like the information you present here and can’t wait to take a look when I get home.
    I’m shocked at how fast your blog loaded on my cell
    phone .. I’m not even using WIFI, just 3G .. Anyways, wonderful blog!

  15. Very helpful post!
    I really enjoyed the manner you covered this subject.

    It’s so good to come across valuable information like this on the web.

    Thanks for taking the time to write.
    Keep up the good work!

  16. Hi there, its nice article on the topic of media print, we all know media is
    a impressive source of data.