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. Nice blog here! Also your website loads up very fast! What web host are you using?
    Can I get your affiliate link to your host? I wish my web site loaded up as quickly as yours lol

  2. This is really fascinating, You are a very skilled blogger.
    I have joined your feed and sit up for in the hunt for more of your magnificent
    post. Also, I have shared your web site in my social networks

  3. Oh my goodness! Incredible article dude! Thank you, However I am going through troubles with your RSS.

    I don’t know the reason why I can’t join it. Is there anyone else having
    similar RSS problems? Anyone that knows the answer will you kindly
    respond? Thanks!!

  4. Nice post. I was checking continuously this blog and I am impressed!
    Very helpful information specially the last part :) I care for such info a
    lot. I was seeking this certain information for a very long time.
    Thank you and best of luck.

  5. First of all I want to say superb blog! I had a quick question which
    I’d like to ask if you don’t mind. I was curious to know
    how you center yourself and clear your head prior to writing.
    I’ve had a hard time clearing my mind in getting my thoughts out.
    I truly do enjoy writing but it just seems like the first 10 to 15
    minutes are wasted simply just trying to figure out how to
    begin. Any recommendations or tips? Thank you!

  6. I love your blog.. very nice colors & theme. Did you make this website yourself or did you
    hire someone to do it for you? Plz reply as I’m looking to design my own blog and would like to find out where u got this
    from. thank you

  7. You actually make it seem so easy with your presentation but I find this matter
    to be really something that I think I would never understand.
    It seems too complicated and very broad for me.

    I am looking forward for your next post, I’ll try to get the hang of it!

  8. Hi there, yup this post is truly fastidious and I have learned lot
    of things from it on the topic of blogging.
    thanks.