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. Hi there to every body, it’s my first pay a visit of this web site;
    this weblog includes remarkable and truly good stuff in favor of readers.

  2. Grateful realizing there’s an individual who cares without a doubt about Jstomer satisfaction typical!!!Explore trending discussions going down accurate now through: ### anyKeyWord ### Plumber Norwich

  3. I appreciate hearing about real-world applications of digital marketing strategies like those used by Webjuice—it helps demystify the process for many of us out there trying our best as franchisees # # anyKeyWord## Franchise SEO

  4. Hey there just wanted to give you a quick heads up and let you
    know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the
    same results.

  5. Hello there! This blog post couldn’t be written much better!
    Reading through this article reminds me of my
    previous roommate! He continually kept talking about this.
    I am going to forward this article to him. Fairly
    certain he’ll have a great read. I appreciate you for sharing!

  6. InfoJunkie is a smart Content discovery software and powerful AI tool that helps you save content, gain insights,
    capture ideas, and grow your knowledge with tools designed to improve
    your learning experience.

  7. This is my first time pay a quick visit at here and i am genuinely happy to read all at one place.

  8. Excellent blog you have here but I was curious about if you knew
    of any community forums that cover the same topics talked
    about in this article? I’d really like to be a part of online community where
    I can get responses from other experienced individuals that share the same interest.
    If you have any recommendations, please let me
    know. Cheers!

  9. Hello! This post couldn’t be written any better!
    Reading this post reminds me of my previous room mate!
    He always kept talking about this. I will forward this page to him.
    Fairly certain he will have a good read. Thank you for sharing!