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’m not sure where you are getting your information, but great topic.
    I needs to spend some time learning more or understanding more.
    Thanks for fantastic information I was looking for
    this information for my mission.

  2. Howdy, I believe your blog could be having web browser compatibility issues.
    When I take a look at your site in Safari, it looks fine however, when opening in I.E., it has some overlapping issues.
    I just wanted to provide you with a quick heads up!
    Other than that, fantastic site!

  3. all the time i used to read smaller posts that as well clear their motive,
    and that is also happening with this article which I
    am reading at this time.

  4. Someone necessarily lend a hand to make significantly articles I’d state.
    This is the first time I frequented your website page and so far?
    I surprised with the research you made to make this particular put up amazing.
    Magnificent activity!

  5. Excellent pieces. Keep writing such kind of info on your
    site. Im really impressed by your site.
    Hey there, You have done a fantastic job. I’ll definitely digg it and individually suggest to my
    friends. I’m sure they will be benefite from this site.

  6. It is actually a nice and useful piece of information. I am glad that you just shared this useful information with us.

    Please keep us informed like this. Thank you for sharing.