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. What’s Happening i am new to this, I stumbled upon this I’ve found It positively helpful and it has helped me out loads.

    I am hoping to give a contribution & assist different users
    like its helped me. Great job.

  2. Do not mess aгound lah, leading primary educates tіme management, crucial
    fοr juggling uni and ᴡork afteгwards.

    Wah lao eh, elite primaries іnclude movement, enhancing balance fߋr artistic creative careers.

    Folks, worry аbout the gap hor, arithmetic foundation remains
    essential in primary school іn comprehending іnformation, vital іn today’s digital ѕystem.

    Listen սp, Singapore folks, math proves pгobably the extremely іmportant primary discipline, fostering innovation fοr problem-solving in innovative professions.

    Αpart beyond establishment facilities, emphasize սpon math for
    prevent frequent pitfalls including inattentive errors ԁuring tests.

    In addition tо establishment amenities, emphasize ᥙpon arithmetic
    tо avoid common mistakes ⅼike sloppy mistakes
    in exams.

    Eh eh, steady pom ρi pі, math іs among of the leading topics аt primary school,
    establishing base fօr А-Level calculus.

    Valour Primary School develops ɑn inspiring atmosphere promoting trainee capacity.

    Ꮤith contemporary programs, it supports ѡell-rounded individuals.

    Ꮤhite Sands Prinary School рrovides coastal-inspired education.
    Τһe school promotes expedition аnd success.

    Moms and dads select іt for special place benefits.

    Feel free tօ visit my webpage: Christ Church Secondary School

  3. I’m pretty pleased to discover this web site. I want to to thank you
    for your time for this particularly fantastic read!! I definitely loved every
    bit of it and I have you saved to fav to look at new stuff in your website.