以下の内容はhttps://ohbarye.hatenablog.jp/entry/2018/08/01/000517より取得しました。


必要なときだけ Polyfill.io のCDN から polyfill を読み込むようにする

以下のような script tag を HTML の最初の script tag として埋め込む。

<script>
(
  function(doc){
    if([].find&&window.fetch)return;

    var firstScript = doc.getElementsByTagName('script')[0];
    var scriptToInsert = doc.createElement('script');
    scriptToInsert.src='https://cdn.polyfill.io/v2/polyfill.min.js?features=Array.prototype.find,fetch';
    firstScript.parentNode.insertBefore(scriptToInsert, firstScript);
  }(document)
)
</script>

無名関数の1行目で polyfill が必要かどうかを判定する。

必要であれば、cdn.polyfill.io から polyfill を得るための script tag を document に埋め込む。

doc.getElementsByTagName('script')[0] より前に insert しているのは polyfill が読み込まれる前に script が実行されるのを防ぐため。


Polyfill.io については https://polyfill.io/v2/docs/api を参照




以上の内容はhttps://ohbarye.hatenablog.jp/entry/2018/08/01/000517より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14