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 read this paragraph completely regarding the resemblance of most recent and previous technologies, it’s awesome article.

  2. Hello there! This post could not be written any better! Reading through this post
    reminds me of my old room mate! He always kept chatting about this.
    I will forward this article to him. Pretty sure he
    will have a good read. Thanks for sharing!

  3. What you published made a great deal of sense. However, what about this?
    what if you wrote a catchier title? I mean, I don’t want to tell you how to run your blog, but suppose you added something to possibly grab folk’s attention? I mean jQuery
    CDN as A Named Module In RequireJS | freestyle developments is a little
    plain. You might peek at Yahoo’s home page and see how they create post titles
    to get viewers to open the links. You might try adding a video or a
    picture or two to get people excited about everything’ve written. In my opinion, it might bring your website a little bit
    more interesting.

  4. After going over a handful of the blog articles on your blog, I honestly like your technique of blogging.
    I added it to my bookmark site list and will be checking back in the near
    future. Take a look at my website too and let me know
    your opinion.

  5. Hey There. I found your blog using msn. This is a very well written article.
    I will be sure to bookmark it and come back to read more of your useful information. Thanks for the post.
    I’ll definitely comeback.

  6. Aw, this was a really nice post. Spending some time
    and actual effort to create a very good article… but what can I say… I hesitate a whole lot and don’t
    seem to get anything done.