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. There is little authority in English law concerning the rights and duties of a member of the armed forces of the Crown when acting in aid of the civil power; and
    what little authority there is relates almost entirely to the duties of soldiers
    when troops are called upon to assist in controlling a riotous assembly.
    In contrast to this a soldier who is employed in aid of
    the civil power in Northern Ireland is under a duty, enforceable under military law,
    to search for criminals if so ordered by his superior officer and to risk his own life should this be necessary in preventing terrorist acts.
    In theory it may be the duty of every citizen when an arrestable offence is about to be committed in his presence
    to take whatever reasonable measures are available to him to prevent the commission of the
    crime; but the duty is one of imperfect obligation and it does
    not place him under any obligation to do anything by which he would expose
    himself to risk of personal injury, nor is he under any duty to search for criminals or
    seek out crime.

  2. We’re a bunch of volunteers and opening a brand new scheme
    in our community. Your web site provided us with useful information to work on. You have performed a formidable
    job and our whole community can be thankful to you.

  3. I for all time emailed this blog post page to all my friends, as if like to read
    it after that my contacts will too.

  4. Have you ever thought about creating an e-book or guest authoring on other sites?
    I have a blog based on the same topics you discuss
    and would love to have you share some stories/information. I
    know my audience would enjoy your work. If you’re even remotely interested, feel free to shoot me an email.

  5. I quite like looking through an article that can make people think.

    Also, thank you for allowing me to comment!

  6. Have you ever thought about creating an ebook or guest authoring on other sites?
    I have a blog centered on the same ideas you discuss and would really like
    to have you share some stories/information. I know my
    readers would enjoy your work. If you’re even remotely interested, feel free to send me an e-mail.