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. Oh my goodness! Impressive article dude! Thanks, However I
    am having issues with your RSS. I don’t understand why I cannot subscribe
    to it. Is there anyone else getting the same RSS issues?

    Anyone who knows the answer will you kindly respond? Thanx!!

  2. Do you have a spam issue on this website; I also am a blogger,
    and I was curious about your situation; we have created some nice procedures and we are looking
    to exchange methods with others, be sure to shoot me an e-mail if interested.

  3. Excellent way of telling, and pleasant paragraph to obtain data on the topic of
    my presentation topic, which i am going to convey in university.

  4. Fantastic post however , I was wanting to know if you could write a litte more on this subject?
    I’d be very grateful if you could elaborate a
    little bit further. Kudos!

  5. I’m curious to find out what blog platform you are utilizing?
    I’m experiencing some small security issues with my latest blog and I would like to find something more safeguarded.

    Do you have any suggestions?

  6. That is very attention-grabbing, You are an excessively skilled blogger.
    I have joined your rss feed and look forward to searching for more of your fantastic post.
    Additionally, I have shared your site in my social networks

  7. Its such as you read my mind! You seem to grasp so much
    about this, like you wrote the guide in it or something.
    I think that you can do with a few percent to pressure
    the message house a bit, but other than that,
    that is fantastic blog. A fantastic read. I will definitely
    be back.

  8. My brother recommended I might like this blog. He was totally right.
    This post actually made my day. You cann’t imagine simply how much time
    I had spent for this information! Thanks!

  9. ข้อมูลชุดนี้ อ่านแล้วเข้าใจง่าย ครับ

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

    จะรอติดตามเนื้อหาใหม่ๆ ต่อไป

  10. Hello! I could have swworn I’ve visited this webxite before but after lookking at some
    of the posts I realized it’s new to me. Nonetheless, I’m definitely pleased I stumbled upon itt and I’ll
    be book-marking it and checking back frequently!

    Here is my blog – wancoy168

  11. Heya this is somewhat of off topic but I was wanting
    to know if blogs use WYSIWYG editors or if you have to
    manually code with HTML. I’m starting a blog soon but have no coding skills
    so I wanted to get guidance from someone with experience.

    Any help would be enormously appreciated!

  12. Pretty section of content. I just stumbled upon your web site and in accession capital to assert that I acquire actually enjoyed account your blog posts.
    Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.

  13. Hi, i think that i saw you visited my blog so i came to
    “return the favor”.I am trying to find things to enhance my site!I suppose its ok to use a few of your ideas!!

  14. Ahaa, its fastidious dialogue on the topic of this post here at this webpage, I have
    read all that, so at this time me also commenting at this place.