Zepto fallback to jQuery

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

    While many of the existing answers work fine when loading Zepto.js via an additional request, I have a situation where I know Zepto will suffice most of the time and I just want to merge it in with my scripts and lazily load jQuery if needed. I put together a small wrapper for Zepto will do just that.

    • Zepto conditional loading wrapper

    It runs the "offical" '__proto__' in ... test and lazy loads jQuery if it fails. If it succeeds, then it continues loading Zepto.

    I found that IE8 would blow up if Zepto was even loaded. This fixes that by skipping the rest of the module.

    For the optimistic case, there isn't any additional script requests. For the jQuery path, well, those users weren't exactly getting the fast experience anyway.

提交回复
热议问题