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. Excellent web site. Lots of useful info here.
    I am sending it to some friends ans also sharing in delicious.
    And naturally, thank you to your effort!

  2. My brother suggested I would possibly like this web site.
    He was once entirely right. This publish actually made my day.
    You can not imagine simply how a lot time I had spent for this info!
    Thanks!

  3. We are a bunch of volunteers and starting a new scheme in our community.
    Your web site offered us with useful information to work on.
    You’ve performed an impressive job and our entire neighborhood
    will probably be thankful to you.

  4. Hey! Someone in my Facebook group shared this website with us so I came to give it a look.
    I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers!
    Terrific blog and brilliant design and style.

  5. Valuable information. Fortunate me I discovered your site by chance, and I’m stunned why this twist of fate didn’t happened in advance!
    I bookmarked it.

  6. Hey! I know this is kinda off topic however ,
    I’d figured I’d ask. Would you be interested in trading links
    or maybe guest authoring a blog post or vice-versa?
    My site discusses a lot of the same subjects as yours
    and I feel we could greatly benefit from each other.

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

  7. You can feel extreme pain or discomfort in the lower abdomen if you’re not able
    to urinate for a long time. Can you read the numbers on the ruler in the
    penile enlargement photo?