3

Polyfill.io cheatsheet

 2 years ago
source link: https://devhints.io/polyfill.io
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Polyfill.io is a service that serves JavaScript polyfills.

Default usage

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

This is the default script for Polyfill.io.

References

#Optimized

For modern browsers

<script>if(!(window.Promise&&[].includes&&Object.assign&&window.Map)){document.write('<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></scr'+'ipt>')}</script>

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

Extra features

<script>if(!(window.fetch&&window.Promise&&[].includes&&Object.assign&&window.Map)){document.write('<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch"></scr'+'ipt>')}</script>

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK