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. Wow, that’s what I was searching for, what a data! present here at this weblog, thanks
    admin of this site.

  2. I was recommended this blog by my cousin. I am not sure whether this post
    is written by him as no one else know such detailed
    about my trouble. You are incredible! Thanks!

  3. You could certainly see your skills in the work you write.
    The world hopes for even more passionate writers like you who aren’t afraid
    to say how they believe. Always follow your heart.

  4. Hi there to every one, for the reason that I am in fact keen of reading this weblog’s
    post to be updated on a regular basis. It consists of good material.

  5. Hello woulld you mind lettting me know which webhost you’re utilizing?
    I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot quicker theen most.
    Can you recommend a good hosting provider at a honesst price?
    Kudos, I appreciate it!

  6. Definitely believe that which you stated. Your favorite justification appeared to be on the web the
    easiest thing to be aware of. I say to you, I definitely get annoyed while people consider
    worries that they plainly do not know about.
    You managed to hit the nail upon the top and defined
    out the whole thing without having side effect , people can take
    a signal. Will probably be back to get more. Thanks

  7. My partner and I absolutely love your blog and find nearly all of your post’s
    to be exactly what I’m looking for. can you offer guest writers to
    write content to suit your needs? I wouldn’t
    mind publishing a post or elaborating on most of the subjects you
    write in relation to here. Again, awesome web site!

  8. Hey there! Do you use Twitter? I’d like to follow you if that would be okay.
    I’m absolutely enjoying your blog and look forward to new posts.

  9. Hi! I know this is somewhat off topic but I was wondering if you knew where I could find a
    captcha plugin for my comment form? I’m using the
    same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!