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. Does your site have a contact page? I’m having problems locating it but, I’d like to shoot you an e-mail.
    I’ve got some recommendations for your blog you might be interested
    in hearing. Either way, great site and I look forward to seeing it
    develop over time.

  2. Nice post. I was checking continuously this blog and I am impressed!

    Extremely useful information specially the last part :
    ) I care for such information a lot. I was seeking this
    certain info for a long time. Thank you and
    good luck.

  3. I’m so joyful I chose this service provider for my plumbing desires—high quality adventure universal! More info should be would becould very well be came upon at Plumber Norwich .

  4. Hi would you mind letting me know which web host you’re working with?
    I’ve loaded your blog in 3 different browsers and I must say
    this blog loads a lot faster then most. Can you recommend a good web
    hosting provider at a fair price? Thanks, I appreciate it!

  5. Monitoring CPU temperature on Raspberry Pi is an important part of IoT device
    management. Real-time IoT monitoring ensures stability, efficiency,
    and reliable operation in both DIY and professional projects.

  6. High-performance drill pipes are made from durable steel and
    feature threaded tool joints for secure connections.
    They provide smooth rotation, stable circulation, and
    extended service life, making them indispensable in mining,
    petroleum, and geological drilling operations.

  7. you’re in reality a excellent webmaster. The website
    loading velocity is amazing. It kind of feels
    that you are doing any distinctive trick. Furthermore, The contents are masterpiece.
    you’ve performed a wonderful job in this subject!

  8. Our GRC planters and furniture are crafted for durability and style.

    Greenery Notion, a trusted China GRC factory, offers
    custom designs for outdoor spaces, gardens, patios,
    and commercial projects, delivering high-quality concrete solutions.

  9. Do you have a spam problem on this site; I also am a blogger, and
    I was curious about your situation; we have created some nice
    practices and we are looking to exchange solutions with
    other folks, be sure to shoot me an email if interested.

  10. You actually make it seem so easy with your presentation but
    I find this topic to be really something which 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!