Promise, EventSource, and document.querySelectorAll().
Older versions of the JavaScript SDK require the LaunchDarkly EventSource polyfillIn the JavaScript SDK, v3.x and earlier, if you use
REPORT, enable the useReport configuration option, and want to use streaming, then you must use the LaunchDarkly EventSource polyfill. This is true whether or not your browser already supports EventSource. To learn more, read EventSource, below.The JavaScript SDK v4.x does not use the LaunchDarkly EventSource polyfill. To stream with the REPORT method, set the eventSource configuration option to an EventSource implementation that supports custom HTTP methods. In v4.14 and later, LaunchDarkly provides an out-of-the-box implementation that supports REPORT and POST. To learn how to use it, read the custom EventSource example. To use POST requests with the Runtime Delivery Network (RDN), read Send the context in the request body.Add a polyfill
For each of these features, there are two ways you can provide the polyfill script. The first way is to load the polyfill script directly from a CDN that hosts the package, with a<script> tag within the <head> element of your page. You must put the <script> tag for the polyfill before any scripts that make use of the LaunchDarkly SDK.
Here is how to load a polyfill script directly from a CDN:
require() to load modules at runtime, you would first add the polyfill package to your project:
require the polyfill module prior to initializing the LaunchDarkly client:
Install polyfills for specific features
Three features that the LaunchDarkly SDK uses that may not be available on every browser arePromise, EventSource, and document.querySelectorAll(). This section describes how to install a polyfill for each of them.
Promise
The JavaScript SDK relies heavily on JavaScript Promises. Browsers that do not support Promise include Internet Explorer and older versions of Microsoft Edge. If you need to support these browsers, you will need to install a polyfill for Promise, such as es6-promise. To install a polyfill for Promise:EventSource
The JavaScript SDK usesEventSource to provide a live streaming connection to LaunchDarkly, if you have enabled streaming.
By default, the JavaScript SDK client opens a streaming connection if you subscribe to change or change:flag-key events. You can also open a streaming connection explicitly by setting the streaming configuration option or using the setStreaming method. If you never enable streaming, you do not need EventSource. To learn more, read streaming.
EventSource is widely available in modern browsers. If you need streaming and the older browser versions you are supporting do not provide EventSource, you can install a polyfill.
In the JavaScript SDK, v3.x and earlier, if you enable the JavaScript SDK’s useReport configuration option and want to use streaming, you must install the LaunchDarkly EventSource polyfill to provide streaming support. This is true whether or not your browser already supports EventSource.
The JavaScript SDK v4.x does not use the LaunchDarkly EventSource polyfill. To stream with the REPORT method, set the eventSource configuration option to an EventSource implementation that supports custom HTTP methods. In v4.14 and later, LaunchDarkly provides an out-of-the-box implementation that supports REPORT and POST. To learn how to use it, read the custom EventSource example. To use POST requests with RDN, read Send the context in the request body.
To install the LaunchDarkly EventSource polyfill in the JavaScript SDK v3.x and earlier:
document.querySelectorAll()
The JavaScript SDK usesquerySelectorAll to support click events for Experimentation. If you never use click conversion metrics, you do not need querySelectorAll. To learn more, read Clicked or tapped conversion metrics.
querySelectorAll is widely available in browsers, except in old versions of Internet Explorer. If you want to support these, and you need Experimentation support, you can install a polyfill such as polyfill-queryselector.
To install a polyfill for querySelectorAll: