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. Spot on with this write-up, I actually think this web site needs a great deal
    more attention. I’ll probably be returning to see more, thanks for
    the info!

  2. I know this web page gives quality dependent articles and other stuff, is there any other web page which gives these data in quality?

  3. บทความนี้ มีประโยชน์มาก ครับ
    ดิฉัน ไปอ่านเพิ่มเติมเกี่ยวกับ
    หัวข้อที่คล้ายกัน
    ซึ่งอยู่ที่ สล็อตออนไลน์
    ลองแวะไปดู
    มีการยกตัวอย่างที่เข้าใจง่าย
    ขอบคุณที่แชร์ บทความคุณภาพ นี้
    และอยากเห็นบทความดีๆ แบบนี้อีก

  4. Oh my goodness! Amazing article dude! Many thanks, However I am encountering troubles with your RSS.
    I don’t know the reason why I can’t join it. Is there anybody having the same RSS issues?
    Anyone who knows the answer can you kindly respond?
    Thanx!!

  5. Hi there, You have done an excellent job. I’ll definitely digg it
    and personally suggest to my friends. I am sure they will be benefited from this
    web site.

  6. Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Regardless, just wanted to say wonderful blog!

  7. Hello there! This post could not be written much better!
    Looking at this article reminds me of my previous
    roommate! He always kept preaching about this.
    I most certainly will forward this post to him. Fairly certain he’s going to have a
    great read. Thank you for sharing!

  8. Thank you for any other informative blog. Where else may just I am getting
    that type of info written in such an ideal means?
    I have a project that I’m just now operating on, and I have
    been on the look out for such information.

  9. You really make it seem so easy with your presentation but I
    find this topic to be actually something which I think I would never understand.

    It seems too complicated and extremely broad for me.
    I am looking forward for your next post, I will try to get the
    hang of it!

  10. Hey would you mind letting me know which webhost you’re using?
    I’ve loaded your blog in 3 different web browsers
    and I must say this blog loads a lot quicker then most.
    Can you suggest a good hosting provider at a honest price?
    Cheers, I appreciate it!