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 a very well written article.

    I’ll make sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I will definitely return.

  2. Howdy! Do you know if they make any plugins to protect against hackers?

    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any suggestions?

  3. The other day, while I was at work, my cousin stole my apple ipad and tested
    to see if it can survive a thirty foot drop, just so she can be a youtube sensation. My iPad is now broken and she has
    83 views. I know this is totally off topic but I had to share it with someone!

  4. Oh my goodness! Awesome article dude! Thanks,
    However I am having issues with your RSS. I don’t know why I cannot subscribe to it.
    Is there anybody getting similar RSS problems? Anyone that knows the answer can you kindly respond?
    Thanx!!

  5. I think what you said made a lot of sense. But, what about this?
    suppose you were to create a awesome post title?
    I ain’t suggesting your content isn’t solid., but what
    if you added a title that makes people want more?

    I mean jQuery CDN as A Named Module In RequireJS | freestyle developments is a little vanilla.
    You might look at Yahoo’s home page and see how they create
    news headlines to grab viewers interested. You might add a video or a related picture or two
    to grab readers interested about what you’ve got to say.
    Just my opinion, it would bring your posts a little livelier.

  6. Hello there, I discovered your blog by the use of
    Google even as searching for a similar matter, your
    website came up, it seems to be great. I have bookmarked it in my google bookmarks.

    Hello there, simply became alert to your weblog thru Google,
    and located that it is truly informative. I’m going
    to watch out for brussels. I will be grateful should you proceed this in future.

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

  7. Hello, i feel that i saw you visited my weblog
    thus i got here to go back the prefer?.I am attempting to find things to enhance my
    site!I suppose its good enough to use some of your ideas!!

  8. What’s up to every one, the contents existing at this site are in fact
    awesome for people knowledge, well, keep up the nice work fellows.