Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elegant way to include es6-promise for IE

Since Promise is not support in all IE versions, I would like to make the IE users to download a pollyfill in HTML.

<!--[if IE]>
<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"></script>
<![endif]-->

However, conditional comments are not supported in IE 10 and 11. So the above code doesn't work in IE 10 and 11.

Then, Microsoft provide a workaround.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

This make IE 10 and 11 behave like IE 9.

But my website work only in IE 10+. So this solution isn't suitable to me. Is there any other way to solve this issue?

like image 612
cwtuan Avatar asked Jan 20 '26 18:01

cwtuan


1 Answers

Just use

<script>
    if (typeof Promise !== "function")
        document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><\/script>');
</script>

which does not work only for IE users, but in every environment without a native Promise implementation.

like image 70
Bergi Avatar answered Jan 22 '26 06:01

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!