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. Thanks for sharing your thoughts. I really appreciate your efforts
    and I am waiting for your next write ups thank you once again.

  2. Great insights about luxury villas for sale in Greece!
    Thanks for sharing such valuable information.

    Appreciate the details on these luxury homes.
    Looking forward to more updates!
    more info

  3. I am really inspired with your writing skills and also with the structure to your weblog.
    Is that this a paid theme or did you modify it your self?
    Either way stay up the excellent high quality writing,
    it’s rare to peer a great blog like this one today..

  4. My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on several websites for about a year and am worried about switching to another
    platform. I have heard good things about blogengine.net.
    Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be really appreciated!

  5. Everything said was actually very logical.

    However, what about this? suppose you typed a catchier title?
    I mean, I don’t want to tell you how to run your blog, however what if you added something that grabbed people’s attention? I
    mean jQuery CDN as A Named Module In RequireJS | freestyle developments is kinda plain.
    You should peek at Yahoo’s home page and see how
    they create post headlines to grab people to open the links.
    You might add a related video or a related picture or two to grab
    readers excited about what you’ve got to say.
    Just my opinion, it would make your website a little bit more interesting.