Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:13:29+00:00 2026-06-15T04:13:29+00:00

I’ve seen pages that instruct or ask how to fallback from Zepto to jQuery

  • 0

I’ve seen pages that instruct or ask how to fallback from Zepto to jQuery (especially for IE), as here on SO and here on Zepto.js official page.
I’ve also seen examples on how to fallback from Google-hosted jQuery to a local site jQuery, as in Modernizr.load doc page.

My question is, how do I put the two things together? Possibly also without using Modernizr.load, just using proper <script> blocks?

Here’s what I came up with, but it seems IE never finds the Google hosted version. Also, I’m not sure the Zepto = jQuery assignment works properly.

<script>
    document.write('<script src=' +
        ('__proto__' in {} ? 
            'js/vendor/zepto.min' : 
            'https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min') +
        '.js><\/script>');
</script>
<script>
    if (window.jQuery) { 
        window.Zepto = window.jQuery; /* let jQuery alias Zepto */ 
    }
    else
    { /* here jQuery could be rightly undefined because Zepto is loaded, 
         so this could be wrong. */
        document.write('<script src=' +
            'js/vendor/jquery-1.8.0.min' +
            '.js><\/script>');
    }
</script>
<script>
    if (window.jQuery) { 
        window.Zepto = window.jQuery; /* let jQuery alias Zepto */ 
    }
    else
    {
        /* same problem as before */
        console.error('Zepto nor jQuery available!');
    }
</script>

Is there a better way? TA

Edit

After @Ashfame answer, this is what I’ve used:

<!-- Load local Zepto.js or (as a fallback) jQuery from Google CDN or (as a fallback) local jQuery -->
<script>
    document.write('<script src="' + ('__proto__' in {} ? 
        'js/vendor/zepto' : 
        'http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery') + 
        '.min.js"><\/script>')
</script>
<script>
    window.Zepto || window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>');
</script>

I could not use the protocol-less/scheme-less URL of Google CDN as for some reason it didn’t work on my local IE9 (it waits a lot, then always falls back to local).

I did not aliased anymore Zepto with jQuery: just used $ in JS code.

I don’t seem to experience any problem related to jQuery loading out of order w.r.t. dependent code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:13:30+00:00Added an answer on June 15, 2026 at 4:13 am

    For the sake of trying this technique out, I would try this first:

    I wrote this quickly along the line of how HTML5 Boilerplate loads a local fallback when jQuery CDN is down.

    This might not work, but I don’t see any reason why it shouldn’t right now. Wanna give it a spin?

    <script>document.write('<script src="' + ('__proto__' in {} ? 'cdn/zepto.min' :  'cdn/jquery.min') + '.js">\x3Cscript>');</script>
    <script>window.Zepto || window.jQuery || document.write('<script src="cdn/jquery.min.js">\x3C/script>')</script>
    <script>window.Zepto || window.jQuery || document.write('<script src="local/jquery.min.js">\x3C/script>')</script>
    

    The only case it won’t handle well is when the user is on a non-Zepto compatible browser like IE & at the same time jQuery CDN is down, then it will try to load the jQuery CDN again once and then ultimately fallback to local copy of jQuery.


    But practically speaking, if I were to implement this, I would just have 1 single fallback to local. Like try checking whether we can load Zepto, or jQuery, and in the next step, if neither of them was loaded, load local library. Better to have something working in place, rather than trying to optimize something which won’t return that much gain. Optimize wisely! It can be very likely that the above technique #1 will have its own cavets of cross browser compatibilities.


    I just found out this issue where it says, even this technique (being used & recommended by HTML5 Boilerplate & Modernizr) is not reliable. Check this issue – document.write fallback causing jQuery to load out of order

    Another solution in that question talks about a library Yepnope. You can check how it works – https://stackoverflow.com/a/12323328/551713

    Lastly I would end this answer by saying that unless you are building something that will totally be your code, like not running into the wild with the possibilities of its user adding more stuff on the page, don’t bother yourself about it that much because you will quickly run into issues with such techniques, because other script might load out of order and cause issues, whereas if its all your code, you can probably make everything load & work as per your logic of fallbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.