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 absolutely love your blog and find most of your post’s to be
    exactly what I’m looking for. Do you offer guest writers to write content for
    you personally? I wouldn’t mind producing a post or elaborating on many of the subjects you write concerning here.
    Again, awesome weblog!

  2. Kaizenaire.com leads ɑs Singapore’s leading syѕtеm for deals, events, and shopping
    promotions.

    Ƭhe adventure оf promotions in Singapore’ѕ shopping heaven қeeps Singaporeans
    returning fоr more deals.

    Birdwatching in Sungei Buloh Wetland Reserve mesmerizes nature-loving Singaporeans, аnd remember
    tօ stay upgraded on Singapore’ѕ most гecent promotions
    and shopping deals.

    Singlife оffers digital insurance polcy
    ɑnd cost savings products, appreciated Ƅу Singaporeans for tһeir tech-savvy
    technique аnd economic security.

    Ong Shunmugam reinterprets cheongsams ᴡith contemporary twists mah, loved Ƅү culturally honored Singaporeans fοr
    their blend of tradition аnd innovation sia.

    Marigold nourishes ԝith milk аnd fruit drinks, loved Ƅy households for trusted tⲟp quality in yogurts
    and milks tһat sustain everyday wellness.

    Eh, wise relocation mah, surf Kaizenaire.сom repeatedly lah.

    Also visit my blog; Kaizenaire.com Loans

  3. I am extremely impressed with your writing skills as well as with the layout on your blog.
    Is this a paid theme or did you modify it yourself?
    Anyway keep up the nice quality writing, it’s rare to see a nice blog like this one today.

  4. I’m really impressed with your writing skills and also with
    the layout on your weblog. Is this a paid theme or did you modify it
    yourself? Anyway keep up the nice quality writing, it’s rare to see
    a great blog like this one these days.

  5. I visited various sites except the audio quality for audio songs current at this web site
    is really wonderful.

  6. Hey there, You have done an incredible job. I’ll definitely digg it and
    personally suggest to my friends. I’m confident they’ll be benefited from this site.