1. What is Polyfill?
Polyfill
It is a js
library that mainly smoothes the differences in js implementation between different browsers. For example, html5
the storage
( session
, local
), different browsers, different versions, some support, some do not support. Polyfill
( Polyfill
There are many, GitHub
on https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills ) to help you smooth out these differences, and those that are not supported become supported (typically in window.XMLHttpRequest is added in IE browser, and ActiveXObject is used for internal implementation.)
Mention Polyfill
, have to mention shim
, polyfill
is shim
a kind of.
shim
Is to api
encapsulate into one, such as jQuery
the $.ajax
encapsulation of andXMLHttpRequest
to create objects in a way. It introduces a new one into an old environment, and implements it only by the means already in the old environment.IE
ActiveXObject
xhr
API
2. How to use?
Directly import the project, the easiest is CDN:
<script src="//cdn.polyfill.io/v1/polyfill.min.js" async defer></script>