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. Hello, i think that i noticed you visited my site so i got here to return the choose?.I am attempting to in finding issues to
    enhance my website!I assume its ok to use some of your
    ideas!!

  2. 日立エンジニアリングは家電メンテナンス、電気通信・空調設備、施工管理から多岐にわたる人材派遣サービスまで展開する企業です。優れたシステムを支える「人」の力を大切にし、社員一人ひとりを「人財」として育成。生活インフラの保守や多様なサービスを通じて社会に貢献し、社員が誇りを持てる企業を目指しています。

  3. Hi there, I found your site by means of Google even as searching
    for a related matter, your site came up, it looks
    great. I have bookmarked it in my google bookmarks.

    Hi there, just became aware of your blog thru Google, and located that it’s really informative.
    I’m going to watch out for brussels. I’ll be grateful in case you proceed this in future.

    Many other people will be benefited from your writing. Cheers!

    Check out my homepage … 免费A片 – Roberto,

  4. Nice weblog here! Also your website rather a lot up
    very fast! What web host are you the usage of?

    Can I am getting your affiliate hyperlink on your host?
    I wish my site loaded up as quickly as yours lol