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. Great post however I was wanting to know if you could write
    a litte more on this topic? I’d be very grateful if you could elaborate a little bit
    more. Appreciate it!

  2. Hello everyone, it’s my first pay a quick visit at this web site, and piece of writing is really fruitful for me,
    keep up posting these types of posts.

  3. whoah this weblog is excellent i love studying your articles.

    Stay up the great work! You already know, many individuals are hunting around for this
    information, you can aid them greatly.

  4. great points altogether, you simply won a new reader. What would you suggest about your submit that you just made a few days ago?
    Any certain?

  5. Definitely believe that that you stated. Your favourite reason seemed
    to be at the net the simplest thing to remember of. I say to
    you, I definitely get irked while other folks consider concerns that they plainly do not know
    about. You controlled to hit the nail upon the top and also outlined out the
    entire thing without having side effect , other folks can take a signal.
    Will probably be back to get more. Thanks

  6. I think the admin of this website is truly working hard in favor of
    his site, for the reason that here every information is
    quality based data.

  7. I’m not that much of a online reader to be honest but your sites really
    nice, keep it up! I’ll go ahead and bookmark your website to come back down the road.

    Cheers

  8. That is a great tip particularly to those new to the blogosphere.

    Brief but very accurate info… Thanks for sharing this
    one. A must read post!

  9. Heya i’m for the primary time here. I came across this board and I in finding It really useful & it
    helped me out much. I am hoping to provide one thing back and aid others such as you aided me.

  10. Hi would you mind sharing which blog platform you’re working with?
    I’m going to start my own blog soon but I’m having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your layout seems different then most blogs and I’m
    looking for something completely unique.
    P.S My apologies for being off-topic but I had to ask!

  11. Hey I know this is off topic but I was wondering if you
    knew of any widgets I could add to my blog that automatically tweet my newest
    twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping
    maybe you would have some experience with something like
    this. Please let me know if you run into anything. I
    truly enjoy reading your blog and I look forward to your new updates.

  12. Pretty great post. I just stumbled upon your weblog
    and wished to mention that I have truly loved browsing your blog posts.
    In any case I will be subscribing in your rss feed and I am
    hoping you write once more very soon!

  13. I think this is one of the most significant info for me.
    And i am glad reading your article. But want to remark on some general things, The website style is ideal, the articles is really nice :
    D. Good job, cheers

  14. My partner and I stumbled over here coming from a different
    page and thought I might as well check things out.
    I like what I see so i am just following you. Look forward
    to looking over your web page for a second time.

  15. Hi there to every one, it’s truly a pleasant for me
    to pay a quick visit this web page, it consists of priceless Information.

  16. Fantastic goods from you, man. I’ve remember your stuff previous to and you’re
    simply too excellent. I really like what you have acquired right here, really
    like what you’re stating and the best way in which you say it.
    You’re making it enjoyable and you continue to take care
    of to keep it smart. I can’t wait to read much more from you.
    That is actually a tremendous website.

  17. You actually make it seem so easy along with your presentation however
    I in finding this matter to be really something which I think I’d by no means understand.
    It kind of feels too complicated and very wide for me.
    I am taking a look forward to your next publish, I’ll try to
    get the grasp of it!

  18. You’re so awesome! I don’t suppose I have read through something like this before.
    So wonderful to find someone with some original thoughts on this subject matter.
    Seriously.. many thanks for starting this up. This web site is one thing that is
    required on the web, someone with some originality!

  19. Hmm it seems like your website ate my first comment (it was super long) so I
    guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog writer but I’m still new to everything.
    Do you have any tips for newbie blog writers?

    I’d genuinely appreciate it.

  20. Undeniably consider that that you stated. Your favorite reason seemed to be on the web the easiest factor to take
    note of. I say to you, I definitely get irked at the same time as folks think about
    concerns that they plainly don’t recognise about. You controlled to hit the
    nail upon the top and defined out the entire thing with no
    need side-effects , other folks can take
    a signal. Will probably be back to get more. Thanks

  21. I need to to thank you for this fantastic read!!
    I certainly loved every little bit of it. I’ve got you book
    marked to check out new stuff you post…

  22. After I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now
    on each time a comment is added I recieve four emails with the same comment.
    Perhaps there is an easy method you can remove me from that service?
    Appreciate it!