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. Ꮇy sρouse and I stumbled oveг heгe from a ⅾifferent web page ɑnd thought
    I miht check things out. I like what I seee sоo
    i am just fߋllowing yⲟu. Look fⲟrward to checking out your web рage yet again.

  2. Navigating the legality and risks of offshore trusts in the U.S. is much like charting a course through unpredictable waters—you need a detailed map and a steady hand. Offshore trusts themselves aren’t illegal per se, but the devil is in compliance. The U Continue reading

  3. Look, as a Canadian player, I’ve learned to always check the wagering requirements before chasing bonuses. I got burned once with a 50x requirement, and trust me, it’s near impossible to clear View website

  4. It’s fascinating to see how craft beer and delta-8 are intersecting in the US, especially given how both appeal to consumers craving novel, localized experiences Find more info

  5. I have been surfing online more than three hours today, yet I never found any interesting article like yours.

    It is pretty worth enough for me. In my view, if all
    website owners and bloggers made good content as you did, the
    net will be much more useful than ever before.

    Review my site … yupoo ysl shoes

  6. I recently moved to Puyallup, and I was shocked by how many pests I encountered in my new home! After doing some research on pest control options, I found that local services are crucial for effective solutions Pest Control Puyallup