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 There. I found your blog using msn. This is an extremely well
    written article. I’ll be sure to bookmark it and return to
    read more of your useful information. Thanks for the
    post. I’ll definitely return.

  2. My spouse and I stumbled over here different website and thought I might as
    well check things out. I like what I see so now i am following you.
    Look forward to going over your web page again.

  3. No matter if some one searches for his required thing,
    therefore he/she wishes to be available that in detail, thus that thing is maintained
    over here.

  4. Wow, amazing weblog structure! How lengthy have you ever been running
    a blog for? you made running a blog glance easy.
    The full look of your web site is magnificent, let alone the
    content material!

  5. That is really attention-grabbing, You are an overly skilled blogger.
    I have joined your rss feed and sit up for in search of extra of your wonderful post.

    Also, I have shared your site in my social networks

  6. When I initially commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get several e-mails with
    the same comment. Is there any way you can remove people from that service?
    Thanks!

  7. What’s Going down i’m new to this, I stumbled upon this I
    have discovered It absolutely useful and it has aided me
    out loads. I hope to contribute & assist other users like its helped
    me. Good job.

  8. Interested in legal advice after a car accident? These Seattle car accident lawyers seem knowledgeable and approachable. Checking out their expertise could be beneficial for anyone dealing with such situations. accident lawyer

  9. Hi i am kavin, its my first time to commenting anywhere,
    when i read this paragraph i thought i could also
    make comment due to this good paragraph.

  10. These are truly enormous ideas in concerning blogging.
    You have touched some fastidious things here.

    Any way keep up wrinting.

  11. Very quickly this web page will be famous amid all blogging and site-building people, due to it’s fastidious content