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. Totally agree with you—Rephrase AI really stands out from the crowd! I actually tried out Kroolo’s Natural mode after reading about it and was honestly pretty surprised at how natural the output sounded Learn here

  2. It’s a pity you don’t have a donate button! I’d certainly donate to this excellent blog!
    I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account.
    I look forward to brand new updates and will share this website with my Facebook group.
    Chat soon!

  3. Hi there, just became aware of your blog through Google, and found
    that it’s really informative. I’m gonna watch out for brussels.
    I will appreciate if you continue this in future. A lot of people will be benefited
    from your writing. Cheers!

  4. Unquestionably believe that which you stated. Your favorite justification appeared
    to be on the net the simplest thing to be aware of. I say to you, I
    definitely get irked while people think about worries that they just do not know about.
    You managed to hit the nail upon the top
    and also defined out the whole thing without having side effect ,
    people could take a signal. Will likely be back
    to get more. Thanks

  5. Hi there! I know this is kinda off topic but I’d figured I’d ask.
    Would you be interested in trading links or maybe guest authoring a blog article or vice-versa?
    My blog goes over a lot of the same subjects as yours and I think we could greatly benefit from each other.

    If you are interested feel free to send me an email.
    I look forward to hearing from you! Terrific blog by the way!

  6. I do not even understand how I stopped up right here, but I believed this publish was good.
    I do not understand who you are but certainly you’re going to a famous blogger should you aren’t already.

    Cheers!

  7. Normally I don’t read post on blogs, but I
    wish to say that this write-up very pressured me to check out and
    do so! Your writing style has been surprised me. Thanks,
    quite nice post.