polyfill.io: Fix conditional loading snippet
This commit is contained in:
parent
2e381a4c77
commit
d5a6d6fb04
|
@ -14,26 +14,22 @@ intro: |
|
|||
```html
|
||||
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
|
||||
```
|
||||
|
||||
{: .-wrap}
|
||||
|
||||
This is the default script for Polyfill.io.
|
||||
|
||||
### References
|
||||
|
||||
- [API example](https://polyfill.io/v2/docs/api) _(polyfill.io)_
|
||||
- [List of features](https://polyfill.io/v2/docs/features) _(polyfill.io)_
|
||||
* [API example](https://polyfill.io/v2/docs/api) _(polyfill.io)_
|
||||
* [List of features](https://polyfill.io/v2/docs/features) _(polyfill.io)_
|
||||
|
||||
## Optimized
|
||||
|
||||
### For modern browsers
|
||||
|
||||
```html
|
||||
<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>
|
||||
<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.
|
||||
|
@ -41,13 +37,7 @@ This only includes polyfill.io when necessary, skipping it for modern browsers f
|
|||
### Extra features
|
||||
|
||||
```html
|
||||
<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>
|
||||
<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>
|
||||
```
|
||||
{: 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.
|
||||
|
|
Loading…
Reference in New Issue