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

  1. Хотите вывести ваш сайт на первые
    позиции поисковых систем
    Яндекс и Google?
    Мы предлагаем качественный линкбилдинг — эффективное решение для увеличения органического трафика и роста конверсий!

    Почему именно мы?

    - Опытная команда специалистов,
    работающая исключительно белыми методами SEO-продвижения.

    - Только качественные и тематические доноры ссылок, гарантирующие стабильный рост позиций.

    - Подробный отчет о проделанной работе и прозрачные условия сотрудничества.

    Чем полезен линкбилдинг?

    - Улучшение видимости сайта в поисковых системах.

    - Рост количества целевых посетителей.

    - Увеличение продаж и прибыли вашей компании.

    Заинтересовались? Пишите нам в личные сообщения — подробно обсудим ваши цели и предложим индивидуальное решение для успешного продвижения вашего бизнеса онлайн!

    Цена договорная, начнем сотрудничество прямо сейчас вот на адрес ===>>> ЗДЕСЬ Пишите обгаварим все ньансы!!!

  2. Wow, amazing blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your site is magnificent, let alone the content!

  3. If some one needs expert view regarding blogging and site-building then i
    propose him/her to visit this website, Keep up the nice work.

  4. I’m really impressed with your writing skills and also with the layout on your
    blog. Is this a paid theme or did you customize it yourself?
    Either way keep up the nice quality writing, it is rare to see a great blog
    like this one nowadays.

  5. This blog was… how do you say it? Relevant!! Finally I’ve found
    something which helped me. Thanks!

  6. Hello, this weekend is pleasant designed for me, as this occasion i am reading this great informative piece of writing here at my home.

  7. The other day, while I was at work, my sister stole
    my iphone and tested to see if it can survive a twenty five
    foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83
    views. I know this is completely off topic
    but I had to share it with someone!