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. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your website?
    My blog is in the exact same area of interest as yours and my users
    would genuinely benefit from some of the information you present here.
    Please let me know if this ok with you. Appreciate it!

  2. You made some really good points there. I checked on the net
    for additional information about the issue
    and found most individuals will go along with your views on this site.

  3. Please let me know if you’re looking for a author for your site.
    You have some really great articles and I feel I would be
    a good asset. If you ever want to take some of the load off, I’d really like to write some articles
    for your blog in exchange for a link back to mine. Please blast me an email if interested.
    Kudos!

  4. Woah! I’m really digging the template/theme of this site.
    It’s simple, yyet effective. A lot off times it’s tough to
    get that “perfect balance” between superb usability and visual appearance.
    I mus say that you’ve done a great joob with this. In addition, the blog loads super quick forr me on Internet explorer.

    Outstanding Blog!

  5. That is really fascinating, You’re a very professional blogger.

    I’ve joined your feed and stay up for in the hunt
    for extra of your fantastic post. Also, I’ve shared
    your web site in my social networks

  6. Today, I went to the beach front with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic but I had to tell
    someone!

  7. Today, while I was at work, my cousin stole my apple ipad and tested to see if
    it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is
    now destroyed and she has 83 views. I know this is totally
    off topic but I had to share it with someone!

  8. I know this if off topic but I’m looking into starting my own blog
    and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100% positive. Any recommendations or advice would be
    greatly appreciated. Appreciate it

  9. โพสต์นี้ น่าสนใจดี ครับ.

    ดิฉัน ไปเจอรายละเอียดของ
    เรื่องที่เกี่ยวข้อง
    ซึ่งอยู่ที่ Chantal.
    เผื่อใครสนใจ
    เพราะอธิบายไว้ละเอียด.

    ขอบคุณที่แชร์ บทความคุณภาพ นี้
    จะรอติดตามเนื้อหาใหม่ๆ ต่อไป.

  10. Today, I went to the beachfront with my children. I found
    a sea shell and gave it to my 4 year old daughter
    and said “You can hear the ocean if you put this to your ear.” She put the shell
    to her ear and screamed. There was a hermit crab inside and
    it pinched her ear. She never wants to go back! LoL I know
    this is entirely off topic but I had to
    tell someone!

  11. Hey there! I could have sworn I’ve been to this blog before but after browsing through some of the
    post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back often!

  12. Nice post. I was checking continuously this weblog and I am
    impressed! Extremely helpful info particularly the remaining part :) I maintain such information a lot.
    I was looking for this particular information for a very long time.
    Thanks and best of luck.

  13. Quality posts is the important to interest the users to pay a quick visit the website, that’s
    what this web page is providing.

  14. We stumbled over here by a different web page and thought I
    might check things out. I like what I see so i am just
    following you. Look forward to going over your web page
    yet again.

  15. It’s really a nice and useful piece of information. I’m happy that you shared this useful info with us.

    Please keep us up to date like this. Thanks for sharing.

  16. You really make it appear so easy with your presentation but I in finding this topic to be actually one
    thing that I think I’d never understand. It kind of feels too
    complicated and extremely extensive for me. I’m taking
    a look forward in your subsequent post, I will try to get
    the hold of it!