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.

20,271 thoughts on “jQuery CDN as A Named Module In RequireJS

  1. What’s Happening i’m new to this, I stumbled upon this I have found It positively
    useful and it has helped me out loads. I hope to give a contribution & aid
    different customers like its aided me. Good
    job.

  2. customized contracting does great work on my house

    tradition contracting eavestrough & roofing kitchner roofing
    kitchner roofing tradition contracting eavestrough & roofing
    tradition-contracting roofing kitchener

  3. Incredible! This blog looks just like my old one!
    It’s on a totally different topic but it has
    pretty much the same layout and design. Outstanding choice of colors!

  4. I recently had my carpet installed by Floor Coverings International St Augustine, and I couldn’t be happier with the results. If you’re looking for flooring in Nocatee, they’re the best! flooring

  5. Hiya! Quick question that’s entirely off topic. Do you know how to make your
    site mobile friendly? My blog looks weird when viewing
    from my iphone4. I’m trying to find a template or
    plugin that might be able to resolve this issue. If you have any recommendations, please share.
    Many thanks!

  6. Delighted with the quality of work from ## pleased with the roofing professionals Basingstoke ##! They actually know how to look after their consumers. Roofer

  7. We are a group of volunteers and opening a brand new scheme in our community.

    Your web site offered us with valuable info to work on. You have
    done an impressive process and our whole neighborhood shall be grateful
    to you.

  8. 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.

  9. Great post. I used to be checking continuously this weblog and I am impressed!
    Very helpful info particularly the final part :) I take care of such info a lot.
    I was looking for this particular information for a long time.

    Thank you and best of luck.

  10. Hi! Quick question that’s entirely off topic.
    Do you know how to make your site mobile friendly?
    My website looks weird when viewing from my iphone 4.
    I’m trying to find a theme or plugin that might be
    able to resolve this problem. If you have any suggestions, please
    share. Thanks!

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>