Skip to content

Internet Explorer and promises

Posted in Dynamics 365, Power Platform, and Revive

Microsoft shows us on Get started with the Microsoft Dynamics 365 Web API (client-side JavaScript) how to create a re-usable function using promises. Between the description and the example is a little note box that points out that Internet Explorer 11 doesn’t implement native promises. Most other browsers support promises natively, IE is the problem child – again.
Microsoft further advises that there are several polyfills and libraries which will implement promises to IE. But they don’t tell you how do this in an effective way.

Detection

As you don’t want to add and load superfluous libraries, you have to detect if the browser has promises implemented. In my first approach I used modernizr. 2KB more just for detection. That is not what I wanted and searched for a plain js solution and found it at stackoverflow.

if(typeof Promise !== "undefined" && Promise.toString().indexOf("[native code]") !== -1)
{
    //Your browser is unsuspecting, paste your polyfill or library here.
}

Agony of choice

Now that we can detect if the browser has implemented promises or not, which polyfill or library should we implement additional? My decision fellt on the smallest possible solution I found – ‘ES6 Promise polyfill’ with only 2KB.

5 Comments

  1. If I understand, I’m replacing this :

    //Your browser is unsuspecting, paste your polyfill or library here.

    By

    the ES6 Promise polyfill script ?

    20.04.2017
    |Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.