1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2026-08-16 14:04:47 +02:00
Files
cheatsheets/polyfill.io.md
2017-10-26 14:10:20 +08:00

1.4 KiB

title, category, updated, layout, intro
title category updated layout intro
Polyfill.io JavaScript libraries 2017-10-26 2017/sheet [Polyfill.io](https://polyfill.io) is a service that serves JavaScript polyfills.

Usage

Default usage

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

{: .-wrap}

This is the default script for Polyfill.io.

References

Optimized

For modern browsers

<script>(function(d,s){
if(window.Promise&&[].includes&&Object.assign&&window.Map)return;
var sc=d.getElementsByTagName(s)[0],js=d.createElement(s);
js.src='https://cdn.polyfill.io/v2/polyfill.min.js';
sc.parentNode.insertBefore(js, sc);
}(document,'script'))</script>

This only includes polyfill.io when necessary, skipping it for modern browsers for faster load times.

Extra features

<script>(function(d,s){
if(window.fetch&&window.Promise&&[].includes&&Object.assign&&window.Map)return;
var sc=d.getElementsByTagName(s)[0],js=d.createElement(s);
js.src='https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch';
sc.parentNode.insertBefore(js, sc);
}(document,'script'))</script>

{: data-line="2,4"}

This is the same as the previous, but also adds a polyfill for window.fetch(). We add a window.fetch check and loads the additional fetch feature.