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.

2,064 thoughts on “jQuery CDN as A Named Module In RequireJS

  1. Hey there! Quick question that’s entirely off topic.
    Do you know how to make your site mobile friendly?
    My website looks weird when viewing from my iphone4. I’m trying to find
    a theme or plugin that might be able to correct this problem.
    If you have any recommendations, please share. With thanks!

  2. Please let me know if you’re looking for a article author for
    your weblog. You have some really great articles and I believe 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 send me an email if interested. Many thanks!

  3. I have read so many articles regarding the blogger lovers
    however this piece of writing is truly a pleasant paragraph, keep it up.

  4. Attractive section of content. I simply stumbled upon your
    website and in accession capital to say that I acquire in fact
    enjoyed account your weblog posts. Anyway I’ll be subscribing in your feeds or even I success you get admission to persistently fast.

  5. Just want to say your article is as astounding. The clarity in your post
    is just nice and i could assume you’re an expert on this subject.
    Well with your permission allow me to grab your feed to keep updated with forthcoming post.
    Thanks a million and please continue the enjoyable work.

  6. Today, I went to the beach front with my children. I found a sea shell
    and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and
    screamed. There was a hermit crab inside and it pinched
    her ear. She never wants to go back! LoL I know this is completely off topic but I had to
    tell someone!

  7. My family every time say that I am killing my time here at web, except I know
    I am getting experience everyday by reading thes nice articles or reviews.

  8. Hi, I do think this is an excellent website. I stumbledupon it ;) I may revisit yet
    again since i have saved as a favorite it. Money and freedom is the best way to change,
    may you be rich and continue to help other people.

  9. Mikigaming selalu menjadi pilihan utama
    bagi para pecinta slot online Pragmatic Play yang menginginkan pengalaman bermain terbaik dan peluang kemenangan yang
    menjanjikan.

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>