fix(docs-infra): use script nomodule to load IE polyfills, skip other polyfills (#24317)
This commit includes two changes: 1. It changes the unreliable dynamic way of loading IE polyfills to use `<script nomodule>` instead - for IE it's equivalent to a regular script tag while modern browsers will ignore it. 2. It removes other polyfills for browsers not supporting `Object.assign` as this API is supported by Chrome 45+, Firefox 34+ and Safari 9+ i.e. it's been supported for some time. Note that as of June 2018 Googlebot uses Chrome 41 to render sites to be indexed. Chrome 41 doesn't support `Object.assign` but it also doesn't support ES6 modules so it'll load polyfills meant for IE - which it should do anyway as it doesn't support most of ES6. Fixes #23647 PR Close #24317
This commit is contained in:
parent
9f877f4416
commit
8be6892777
|
@ -82,31 +82,7 @@
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script nomodule src="generated/ie-polyfills.min.js"></script>
|
||||||
if (window.document.documentMode) {
|
|
||||||
// polyfill IE11 in a blocking way
|
|
||||||
var s = document.createElement('script');
|
|
||||||
s.src = 'generated/ie-polyfills.min.js';
|
|
||||||
document.head.appendChild(s);
|
|
||||||
} else if (!Object.assign) {
|
|
||||||
// polyfill other non-evergreen browsers in a blocking way
|
|
||||||
var polyfillUrl = "https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.find&flags=gated&unknown=polyfill";
|
|
||||||
|
|
||||||
// send a blocking XHR to fetch the polyfill
|
|
||||||
// then append it to the document so that its eval-ed synchronously
|
|
||||||
// this is required because the method used for IE is not reliable with other non-evergreen browsers
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.addEventListener("load", function() {
|
|
||||||
var s = document.createElement('script');
|
|
||||||
s.type = 'text/javascript';
|
|
||||||
var code = this.responseText;
|
|
||||||
s.appendChild(document.createTextNode(code));
|
|
||||||
document.head.appendChild(s);
|
|
||||||
});
|
|
||||||
xhr.open("GET", polyfillUrl, false);
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
//load CE polyfill
|
//load CE polyfill
|
||||||
|
|
Loading…
Reference in New Issue