Requirements and polyfills
Read time: 2 minutes
Last edited: Mar 17, 2023
REPORT, you need the LaunchDarkly EventSource polyfill
useReport configuration option and want to use streaming, you must use the LaunchDarkly EventSource polyfill. This is true whether or not your browser already supports
EventSource. To learn more, read EventSource.
Adding 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:
<script src="[URL of the polyfill script]"></script>
If you are using a package manager such as NPM or Yarn, and using
require() to load modules at runtime, you would first add the polyfill package to your project:
npm install firstname.lastname@example.org
Then, make sure that you
require the polyfill module prior to initializing the LaunchDarkly client:
You only need to use one of these methods. You do not need to use both a CDN and a package manager.
Installing polyfills for specific features
Three features that the LaunchDarkly SDK uses that may not be available on every browser are
document.querySelectorAll(). This section describes how to install a polyfill for each of them.
To install a polyfill for Promise:
<!-- loading polyfill from CDN --><script src="https://email@example.com/dist/es6-promise.auto.min.js"></script>
EventSource to provide a live streaming connection to LaunchDarkly, if you have enabled streaming.
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 browsers, except for Internet Explorer and Microsoft Edge. If you want to support these browsers, and you need streaming support, you can install a polyfill such as event-source-polyfill.
To install a polyfill for EventSource:
<!-- loading polyfill from CDN --><script src="https://firstname.lastname@example.org/src/eventsource.min.js"></script>
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
To install LaunchDarkly's EventSource polyfill:
npm install launchdarkly-eventsource
querySelectorAll to support
click events for Experimentation. If you never use click conversion metrics, you do not need
querySelectorAll. To learn more, read Click 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
<!-- loading polyfill from CDN --><script src="https://email@example.com/querySelector.js"></script>