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,233 thoughts on “jQuery CDN as A Named Module In RequireJS

  1. Great post. I was checking constantly this weblog
    and I’m impressed! Very useful info specially the closing
    part :) I deal with such information a lot. I was looking for this certain info for a very lengthy
    time. Thanks and best of luck.

  2. Heya! I realize this is kind of off-topic however I needed to ask.
    Does managing a well-established website like yours
    require a massive amount work? I’m brand new to running a blog but I do write in my diary every day.
    I’d like to start a blog so I can share my personal experience and views
    online. Please let me know if you have any ideas or tips for new aspiring
    blog owners. Thankyou!

  3. It’s hard to come by well-informed people about this subject, however,
    you seem like you know what you’re talking about! Thanks

  4. I believe that is one of the such a lot
    vital info for me. And i’m happy studying your article.
    But wanna remark on some normal issues, The website taste is wonderful, the
    articles is truly excellent : D. Good activity, cheers

  5. Thank you for the good writeup. It if truth be told used to be a entertainment account it.

    Glance advanced to far brought agreeable from you!
    However, how could we communicate?

  6. It’s truly a great and helpful piece of information. I’m satisfied that you shared this useful information with us.

    Please keep us up to date like this. Thanks for sharing.

  7. Wow, fantastic blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your
    site is great, as well as the content!

  8. It’s actually a great and helpful piece of info. I am happy that
    you just shared this useful information with us.

    Please stay us up to date like this. Thank you for
    sharing.

  9. I was curious if you ever thought of changing the structure of your
    blog? Its very well written; I love what youve got to say.
    But maybe you could a little more in the
    way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

  10. What i do not understood is if truth be told how you’re not actually much more neatly-liked than you may be now.
    You’re so intelligent. You already know thus considerably in relation to this subject,
    made me in my view imagine it from a lot of various angles.
    Its like men and women don’t seem to be involved except it is one thing to accomplish with Lady gaga!
    Your personal stuffs nice. At all times maintain it up!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>