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. Pretty nice post. I just stumbled upon your blog
    and wished to mention that I have truly enjoyed browsing your weblog posts.
    After all I’ll be subscribing to your rss feed and I hope you write again very soon!

  2. Pretty nice post. I just stumbled upon your blog and wanted
    to say that I’ve truly enjoyed browsing your blog posts. After
    all I will be subscribing to your rss feed and I
    hope you write again soon!

  3. If you are going for best contents like I do, simply pay a visit this web site all
    the time because it gives feature contents, thanks

  4. Hi! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading your blog and
    look forward to all your posts! Keep up the excellent
    work!

  5. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web savvy so I’m not 100% positive. Any tips or advice would be greatly appreciated.
    Many thanks

  6. First of all I want to say fantastic blog! I had a quick question which I’d like to ask if you don’t mind.

    I was interested to find out how you center yourself and clear your mind before writing.
    I’ve had a hard time clearing my thoughts in getting my
    ideas out there. I do enjoy writing however it just seems like the first 10 to 15 minutes
    are generally lost simply just trying to figure out how to begin. Any ideas
    or hints? Many thanks!

  7. When someone writes an article he/she maintains the plan of a user in his/her mind that how a user can be aware of it.
    So that’s why this post is outstdanding. Thanks!

  8. Thanks for every other excellent article. The place else may anyone get that
    type of info in such an ideal way of writing? I have a presentation next
    week, and I am on the look for such info.

  9. If some one desires to be updated with newest technologies then he must be
    visit this web site and be up to date every day.