Zepto fallback to jQuery

前端 未结 10 1662
孤独总比滥情好
孤独总比滥情好 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 18:54

    This is an old topic, but it's what came up for me, and I was not happy with the solution overall. Someone in a comment above mentioned that the official zepto test will result in zepto going to FireFix 3.6 instead of JQuery, which I would prefer to avoid if at all possible.

    So, my thought was...test to see if it supports some HTML5 feature AND if it's not IE. This may mean that the larger jQuery will go to more browsers than it should, but I would prefer "working" bloated code to a quick download of nothing. So, anyway, taking the isCanvasSupported() method from Modernizer and the __proto__ test recommended by zepto, I'm thinking this might be a good solution (haven't had a chance to actually test yet):

       var isHtml5AndNotIE     = function() {
            var elem = document.createElement('canvas');
            return '__proto__' in {} && !!(elem.getContext && elem.getContext('2d'));
        };
    

    Then, just use that method in the document.write() as in the examples above or wherever you are defining the path to jquery/zepto.

    The only two browser versions that I could see in a quick cross-reference that support canvas but aren't supported by zepto are: * IOS Safari 3.2 (4+ is supported by Zepto) * Android 2.1 (2.2+ is supported by Zepto)

    http://zeptojs.com/#platforms

    http://caniuse.com/#feat=canvas

提交回复
热议问题