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. With havin so much content do you ever run into any issues of plagorism
    or copyright violation? My blog has a lot of completely unique content I’ve
    either authored myself or outsourced but it looks like a lot of it is popping it up all over the internet without my permission. Do
    you know any techniques to help stop content from being ripped off?

    I’d really appreciate it.

  2. Howdy I am so delighted I found your website, I really found you by mistake, while I was researching on Bing for something else, Anyhow I am here now and would just like to say kudos for
    a marvelous post and a all round thrilling blog (I also love the theme/design), I don’t have time
    to look over it all at the minute but I have saved it and also included
    your RSS feeds, so when I have time I will be back to read a great deal more, Please
    do keep up the fantastic work.

  3. Hi would you mind letting 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 faster then most.
    Can you recommend a good web hosting provider at a fair price?
    Thank you, I appreciate it!

  4. Hiya! I know this is kinda off topic but I’d figured I’d ask.

    Would you be interested in exchanging links or maybe guest writing a blog post
    or vice-versa? My site discusses a lot of the same subjects as yours and I feel we could greatly benefit from each other.
    If you happen to be interested feel free to shoot me an email.
    I look forward to hearing from you! Excellent blog by the way!

  5. I’m gone to say to my little brother, that he should also pay a
    visit this blog on regular basis to take updated from most recent news update.

  6. Having read this I thought it was really enlightening.

    I appreciate you spending some time and energy to put this information together.
    I once again find myself personally spending way too much time
    both reading and commenting. But so what, it was still worth it!

  7. Hi there I am so delighted I found your website, I really found you by
    error, while I was browsing on Bing for something else, Nonetheless I am
    here now and would just like to say kudos for a tremendous post and a all round entertaining blog
    (I also love the theme/design), I don’t have time to go through
    it all at the moment but I have saved it and also added in your RSS feeds, so
    when I have time I will be back to read more, Please do keep up the superb work.