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. I’d like to begin by stating this is not any kind of promotion. This is
    just a genuine personal story that I decided to share because someone might need it.
    In case you’re battling with gambling or even beginning
    to feel like it’s becoming a problem, don’t scroll away just yet.

    I used to be someone who thought a quick flutter couldn’t
    hurt. Initially, it felt like harmless fun—a couple of online slots—nothing serious.

    However, it got worse.
    Without realizing, I was checking odds more than my bank balance.
    Sure, there were wins, but those wins just made it worse.

    I kept running after that high. On a particularly bad weekend,
    I wasted nearly [insert loss amount here, e.g., "$2,000"] in less than two days.
    That was rent money. And still, I told myself I could win it back.

    What’s worse is how I began lying—my family. I was completely
    disgusted with myself, and yet I kept doing it. If that sounds familiar,
    you know what I mean.
    Then I came across this article—and I’m not promoting it—but it changed everything for me.

    I’m not trying to convince you that it’s a miracle fix, but it made me recognize the trap I was in.
    The article didn’t preach. It just laid out the truth in a way
    I’d never heard before. It explained how gambling is more than just a bad hobby, and how everything about it is built
    to make you lose.
    Reading that article, I accepted that I had a problem.

    And more importantly, that I needed to stop. It gave me tools
    that helped me take the hardest step towards quitting.

    Since then, I’ve deleted every betting app I ever had.
    I’ve started being honest again. It’s not easy.
    It’s still a fight sometimes. But I’m staying
    strong.
    If gambling is hurting you, then please read that article.
    {

  2. It’s remarkable to go to see this site and reading the views
    of all friends on the topic of this paragraph, while I
    am also zealous of getting experience.

  3. If you desire to get a great deal from this article then you have to apply such
    methods to your won webpage.

  4. There is definately a great deal to learn about this topic.

    I love all the points you have made.

  5. Fantastic goods from you, man. I have understand your stuff previous to and you are just too wonderful.
    I actually like what you have acquired here, really like what you’re stating and the way in which you say it.
    You make it entertaining and you still care for to keep it wise.
    I can’t wait to read far more from you. This is actually a wonderful website.

  6. Hi there, You have done a fantastic job. I
    will definitely digg it and personally suggest to my friends.
    I’m sure they will be benefited from this website.

  7. Everything is very open with a very clear description of the issues.
    It was definitely informative. Your site is very helpful.
    Thank you for sharing!

  8. It’s hard to come by educated people for this subject,
    however, you sound like you know what you’re talking about!
    Thanks

  9. Hey there! Quick question that’s completely off topic. Do you know how to make your
    site mobile friendly? My site looks weird when viewing from my iphone4.

    I’m trying to find a theme or plugin that might
    be able to resolve this problem. If you have any recommendations, please share.
    Many thanks!

  10. I know this site provides quality based articles or reviews and other stuff, is there
    any other web page which provides these kinds of data in quality?