有条件地加载polyfill [英] Conditionally load polyfills
问题描述
我正在建立一个网站,我的目标群体非常普遍(年龄13岁,所以你好IE9,你好古老的android浏览器),所以我需要polyfills一些东西(视口,计算等)。之前我使用Modernizr和一些条件用户代理来定位IOS 6-7等。然后用yepnope.js我加载特定的polyfills。
I'm building a website which my target group is very general (ages 13-oo, so hello IE9, hello ancient android browser), so I need polyfills for some stuff (viewport, calc etc). Before I used Modernizr and some conditionals user agents to target IOS 6-7 etc. Then with yepnope.js I was loading the specific polyfills.
现在modernizr 3.0已经出来了,我注意到Modernizr.load()已被弃用。此外,不推荐使用yepnope.js库。正如他们在他们的网站上所说的那样
Now that modernizr 3.0 is out, I noticed that the Modernizr.load() is deprecated. Also the yepnope.js library is deprecated. As they say on their website
有一些新的最佳做法,你可能应该遵循。
"There are new best practices that you should likely follow instead."
但我找不到任何一个。谷歌搜索了一段时间后,每个人都推荐Modernizr和Yepnope。但是这个问题是如此新鲜(弃用,新版本的Modernizr),我找不到任何新的替代方法。
But I can't find any of them. After googling for some time everyone recommend Modernizr and Yepnope. But this issue is so fresh (the deprecation, the new version of Modernizr), and I can't find any new alternative method.
可能使用了一些模块加载器(像require.js)会做这个工作吗?如果是,怎么做?
Maybe using of some module loader (like require.js) will do the job? And if yes, how?
推荐答案
我在 https://cdn.polyfill.io 可能满足您的需求。我们有一个大约800个polyfill的库,它们有选择地捆绑在一起,只供需要的用户使用。您可以自己运行该服务,也可以从我们的CDN加载polyfill。
I maintain the polyfill service at https://cdn.polyfill.io which may meet your needs. We have a library of around 800 polyfills, which are bundled selectively and served only to users that need them. You can run the service yourself or just load the polyfills from our CDN.
这篇关于有条件地加载polyfill的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!