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

  1. Excellent blog! Do you have any helpful hints for aspiring writers?
    I’m hoping to start my own site soon but I’m a little lost on everything.
    Would you recommend starting with a free platform like WordPress or go for a paid option? There are so many choices out there
    that I’m totally confused .. Any tips? Appreciate it!

  2. Undeniably believe that which you stated. Your favorite reason seemed
    to be on the net the simplest thing to be aware of. I say to you, I definitely get irked while people consider worries that
    they plainly do not know about. You managed to hit the nail upon the top and defined
    out the whole thing without having side effect , people
    can take a signal. Will probably be back to get more.
    Thanks

  3. Have you came across sure instructing programs really useful or fantastic founded in your knowledge along with your baby’s training thus far ? I’m curious what works high-quality ! ### anyKeyWord### infant daycare

  4. Heya! I’m at work surfing around your blog from my new apple iphone!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Carry on the excellent work!

  5. Everything said made a ton of sense. But, think about
    this, what if you were to write a awesome title? I am not suggesting your content
    isn’t solid., however suppose you added something that grabbed folk’s attention? I mean jQuery CDN as A
    Named Module In RequireJS | freestyle developments is kinda vanilla.
    You could look at Yahoo’s home page and note how they create news titles to get viewers to click.
    You might add a related video or a pic or two to get readers interested about everything’ve got to say.

    In my opinion, it could make your blog a little livelier.

  6. Nice weblog here! Additionally your website so much
    up fast! What host are you the usage of?
    Can I get your associate hyperlink to your host? I want my web
    site loaded up as fast as yours lol

  7. I like the valuable information you provide in your articles.
    I will bookmark your weblog and check again here frequently.

    I’m quite certain I’ll learn many new stuff right here!
    Best of luck for the next!

  8. A motivating discussion is definitely worth comment.
    There’s no doubt that that you should write more on this subject, it might not be a taboo
    subject but generally folks don’t speak about such issues.
    To the next! All the best!!

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>