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, i read your blog occasionally and i own a similar one and i was just curious if you get a lot
    of spam remarks? If so how do you reduce it,
    any plugin or anything you can advise? I get so much lately it’s driving me insane so any support is very much appreciated.

  2. This is a topic which is near to my heart… Cheers!
    Exactly where are your contact details though?

  3. I enjoy what you guys tend to be up too.
    Such clever work and reporting! Keep up the very good works guys I’ve
    incorporated you guys to our blogroll.

  4. Bathroom glass doors for Canopy by Hilton

    1) inline glass shower enclosure consists of two stationary glass panel with U channel
    to fix them with the side wall, one center hinge swing entrance door

    2) interior wall partition consists of one stationary glass wall with U channel to
    fix it with the side wall, one sliding glass door for entrance with soft
    close mechanism for easy opening in or out.
    The glass is frosted laminated glass for impact resistant and privacy purpose

    Welcome to inquiry, we are glad to tailor make for each project

    https://www.newspacehospitality.com/e_productshow/?1353-Bathroom-glass-doors-for-Canopy-by-Hilton-1353.html

  5. Please let me know if you’re looking for a article writer for your
    blog. You have some really great articles and I think I
    would be a good asset. If you ever want to take some
    of the load off, I’d really like to write some articles for your blog in exchange for a link
    back to mine. Please shoot me an e-mail if interested. Many thanks!

  6. Definitely imagine that that you said. Your favorite
    justification seemed to be on the net the easiest factor to keep in mind of.

    I say to you, I certainly get irked even as folks consider worries that
    they plainly don’t recognize about. You managed to hit the nail upon the highest and also outlined out the
    entire thing with no need side-effects ,
    other folks can take a signal. Will likely be again to get more.
    Thank you

  7. This design is steller! You obviously know how to keep a reader
    entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Wonderful job.
    I really loved what you had to say, and more than that,
    how you presented it. Too cool!

  8. Great web site you’ve got here.. It’s difficult to find excellent
    writing like yours nowadays. I seriously appreciate individuals
    like you! Take care!!

  9. Simply got my hands on the latest flagship phone, and I can’t believe all the features it has! If you remain in the marketplace for a new gadget, do not forget to explore what phone store needs to offer!