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,316 thoughts on “jQuery CDN as A Named Module In RequireJS

  1. Quality content is the secret to interest the users to go
    to see the website, that’s what this web page is providing.

  2. It is appropriate time to make some plans for the longer term and it is time to be happy.
    I’ve learn this submit and if I may I wish to counsel you some interesting issues
    or tips. Perhaps you could write next articles relating to this article.
    I wish to read even more things approximately it!

  3. Good way of explaining, and good piece of writing to obtain facts
    concerning my presentation topic, which i am
    going to present in school.

  4. I’m gone to tell my little brother, that he should also go to see this web site on regular
    basis to obtain updated from latest news update.

  5. We’re a group of volunteers and starting a new scheme in our community.
    Your site offered us with valuable information to work on. You’ve done a formidable job
    and our whole community will be thankful to you.

  6. An intriguing discussion is worth comment. I do believe that you ought to write more on this subject matter, it may
    not be a taboo subject but usually folks don’t discuss these
    topics. To the next! All the best!!

  7. Super informativer Beitrag! Gerade bei der Pflege und Sanierung älterer Gartenteiche stoßen viele an Grenzen – Algenplagen, Schlamm, defekte Pumpen oder undichte Folien sind typische Baustellen Teichreinigung Hamburg

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>