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. Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments?
    If so how do you prevent it, any plugin or anything you can advise?
    I get so much lately it’s driving me insane so any assistance is very much appreciated.

  2. Hi there, this weekend is pleasant designed for me,
    because this occasion i am reading this enormous informative piece of writing here at my house.

  3. It’s going to be finish of mine day, except before finish I am reading this enormous post to improve my knowledge.

  4. After going over a handful of the blog articles
    on your website, I seriously like your technique of
    blogging. I bookmarked it to my bookmark website list and will be
    checking back soon. Please check out my website as well and tell me
    what you think.

  5. BJ88 Malaysia – Platform kasino & pertaruhan dalam talian yang
    dipercayai. Deposit pantas, permainan selamat, dan sokongan pelanggan 24/7.

    Daftar sekarang!

  6. BJ88 대한민국에 오신 것을 환영합니다 – 당신의
    승리, 전액 지급. 지금 바로 매력적인 보너스를
    받고, 최고의 게임을 즐기며, 믿을 수 있고 편리한 온라인
    베팅 경험을 시작하세요!

  7. Having read this I thought it was rather enlightening. I appreciate you spending some time and effort to put this article together.

    I once again find myself personally spending a significant amount
    of time both reading and leaving comments. But so what, it was still
    worth it!

  8. My family always say that I am killing my time here at web, however I know I am getting experience everyday by reading thes pleasant articles.

  9. Hi! I know this is sort of off-topic but I needed to ask.
    Does operating a well-established blog such as yours take a large amount of work?
    I am completely new to operating a blog however I do write in my journal everyday.
    I’d like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any kind of suggestions or tips for new aspiring bloggers.
    Thankyou!

  10. Howdy outstanding website! Does running a blog similar to this take a
    large amount of work? I’ve virtually no expertise in computer programming but I had been hoping to start my own blog soon. Anyway,
    should you have any suggestions or tips for new blog owners please share.

    I know this is off subject however I just needed
    to ask. Thank you!

  11. It’s really a nice and useful piece of information. I’m happy that you simply shared this helpful information with
    us. Please keep us informed like this. Thank you for sharing.

  12. Hello my friend! I wish to say that this article is awesome, great written and include almost all
    important infos. I’d like to look more posts
    like this .