Zepto fallback to jQuery

前端 未结 10 1617
孤独总比滥情好
孤独总比滥情好 2020-12-23 18:53

I\'m using ZeptoJS for my web app, but I\'d like to fall back to jQuery if the browser doesn\'t support Zepto. Since IE is the only major browser not supported at the moment

10条回答
  •  失恋的感觉
    2020-12-23 19:00

    You should raise the bar a bit so not only IE8 will get jQuery, but also other older browsers. Zepto for example requires features such as Array.prototype.some.

    Zepto requires much the same features as picoQuery (which is an alternative to Zepto). In picoQuery, they do like this:

    if (Array.isArray) {
       // Modern browser
       // (FF4+, IE9+, Safari 5+, Opera 10.5+, Konq 4.9+, Chrome 5+, etc)
       document.write("");
    }
    else {
       document.write("");
    }
    

    From compatibility tables we have that any browser that supports Array.isArray also supports querySelectorAll(), addEventListener(), dispatchevent, Array.prototype.indexOf and Array.prototype.some - all which are used in Zepto

    picoQuery describes this choice here: http://picoquery.com/the_fallback

提交回复
热议问题