dynamically polyfill features for a script
v0.0.9
一个小脚本,可以在绝对必要的情况下只能在功能时进行多填充 - 在具有本机支持的浏览器上没有浪费的请求! ?
该脚本是〜4.2kb UN缩小(121行) (1.04KB UN缩小且GZPECT) ,〜8.37KB UN用内联注释(121行) (2.12kb Un缩小且GZPERCEND)或〜1.9Kb缩小(1行)(1行)(1 Line )(743b andified and Gzpiffect) 。 ?
有关如何在实时系统上部署项目的注释,请参见部署。
确保您知道您的脚本依赖于哪些功能,并将不在您支持的浏览器上的未本地支持的内容归功于(您可以检查https://caniuse.com/)。
npm i dynamic-polyfiller import React from 'react' ;
import { render } from 'react-dom' ;
//The import below is the bit you need!
import dynamicPolyfill from 'dynamic-polyfiller' ;
dynamicPolyfill (
[ "IntersectionObserver" , "Object.assign" ] ,
'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js' ,
'quicklink();'
) ;dynamicPolyfill();注意:病例敏感 dynamicPolyfill( ["IntersectionObserver", "Object.assign"], 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();' )
onLoad属性添加到调用dynamicPolyfill()函数并传递您的参数的标签string或array预期,但如果您不加载第三方脚本,则可以是空白( '' )或null 。string或array的预期。<script></script>标签链接到此脚本 <script src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js'>
</script>
onLoad属性添加到调用dynamicPolyfill()函数并传递您的参数的标签string或array预期,但如果您不加载第三方脚本,则可以是空白( '' )或null 。string或array的预期。注意:从CDN加载仍会导致潜在浪费的请求?
dynamicPolyfill( 'IntersectionObserver', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();' );
dynamicPolyfill( ["IntersectionObserver", "Object.assign"], ['https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'https://other.cdn.net/script.js'], ['quicklink();', 'otherFunction();'] );
注意:您需要确保在调用实际脚本本身已加载的dynamicPolyfill()函数之前。如果您要自己托管脚本(而不是呼唤CDN),请确保首先包含脚本代码,然后调用该函数。您可以以与上面相同的方式执行此操作,但是如果您不打算从同一文件调用它,则可以将CDN URL替换为通往自己的JS文件的路径。
<script
src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js'
onload='dynamicPolyfill( ["IntersectionObserver", "Object.assign"], 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();')'>
</script>
<script
src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js'
onload='dynamicPolyfill(["IntersectionObserver", "Object.assign"], ['https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'https://other.cdn.net/script.js'], ['quicklink();', 'otherFunction();'])'>
</script>
对于可用的版本,请查看回购版本历史记录。不过,我建议您坚持“最新版本”!
另请参阅参与这个小掘金的贡献者列表!
请阅读有关行为准则的详细信息以及提交拉的请求的过程。
该项目已根据MIT许可证获得许可 - 有关详细信息,请参见许可证文件。