polyfill.io 试用

Polyfill 可以为旧浏览器提供和标准 API 一样的功能。比如你想要 IE 浏览器实现 Promise 和 fetch 功能,你需要手动引入 es6-promise、whatwg-fetch。而通过 Polyfill.io,你只需要引入一个 JS 文件。

<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>

Polyfill.io 通过分析请求头信息中的 UserAgent 实现自动加载浏览器所需的 polyfills。 Polyfill.io 有一份默认功能列表,包括了最常见的 polyfills:document.querySelector、Element.classList、ES5 新增的 Array 方法、Date.now、ES6 中的 Object.assign、Promise 等。

<!DOCTYPE html>
<html lang="en">
<head> 
<meta charset="UTF-8"> 
<title>Document</title>     
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?callback=main" async defer></script> 
<script>  
function main(){            
  var node=document.createElement("script");
  node.src="index.js";             
  document.body.appendChild(node);   
}     
</script> 
</head>
<body> 
</body> 
</html>

参考链接:https://www.jianshu.com/p/3e0bf9a414e3

猜你喜欢

转载自www.cnblogs.com/pengxiangchong/p/11647128.html