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. I do believe all of the ideas you’ve offered for your post.

    They’re very convincing and will certainly work. Still, the posts are too quick for starters.
    May just you please prolong them a little from next
    time? Thank you for the post.

  2. Greetings from Florida! I’m bored at work so I decided to
    browse your website on my iphone during lunch break. I really like the info you provide here and can’t wait to take a look when I get home.

    I’m shocked at how quick your blog loaded on my mobile ..
    I’m not even using WIFI, just 3G .. Anyways, wonderful site!

  3. At this time it sounds like WordPress is the best
    blogging platform available right now. (from what I’ve read) Is that what you
    are using on your blog?

  4. Анын голдорунун статистикасы абдан таасирдүү.Ар бир сезон Гарри Кейн жаңы деңгээлге чыгат. Бул сайтта Гарри Кейндин Бавариядагы оюндары тууралуу кеңири маалымат бар: Гарри Кейн Бавария

  5. Erotic spanking is the act of spanking another person for the sexual arousal or gratification of either or both parties.
    Spanking is very sexy and fun. Feel free to download our best online Spanking collection now for FREE!

  6. Hi! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche.

    Your blog provided us beneficial information to work
    on. You have done a extraordinary job!

  7. Hi there, just became aware of your blog through Google, and
    found that it’s really informative. I am gonna watch out for brussels.
    I’ll be grateful if you continue this in future. Many people will be
    benefited from your writing. Cheers!

  8. Good respond in return of this difficulty with firm arguments and describing all
    regarding that.

  9. Hi there, You have done an incredible job. I’ll certainly digg it and personally suggest to my friends.
    I am sure they’ll be benefited from this site.