LaunchDarkly Developer Documentation

Get started in under 30 minutes.
LaunchDarkly provides feature flags as a service for Java · Python · Ruby · Go · Node.js · PHP · .NET. Control feature launches -- who sees what and when -- without multiple code deploys. Easy dashboard for phased rollouts, targeting and segmenting.
Need more help? write us at support@launchdarkly.com

Get Started    

Front-end flags

JavaScript-heavy web applications (single page apps, for example) may want to take advantage of feature flags on the front-end. LaunchDarkly gives you two options for doing this.

Pass feature flags from the backend via templates

One option is to use your backend SDK to evaluate feature flags (as you would normally) and simply pass the flag values to your front-end in a template. Depending on your templating language, this might look something like this:

<script>
   var flags = {
    enableNewDashboard: {{ ldclient.toggle("new.dashboard.enable", ...) }},
    alternatePage: {{ ldclient.toggle("alternate.page", ...) }}
   };
</script>

At runtime, the flag values will be evaluated during template rendering, yielding the feature flag values to use for each specific user:

<script>
   var flags = {
    enableNewDashboard:  true,
    alternatePage: false
   };
</script>

While this requires a bit of plumbing to set up, it will have lower performance overhead than using the client-side SDK, and has no potential to leak private information to clients.

Use the client-side LaunchDarkly SDK

LaunchDarkly also offers a client-side JavaScript SDK that makes it easy to use feature flags in your front-end code. Refer to the Quickstart guide for integration instructions.

A few things to keep in mind about the client-side SDK. First, if you're using it, your identify call needs to contain all the user information necessary to do targeting properly. In practice that means that the user you pass to identify should be identical to the user you pass in your backend SDK integration. Second, the client-side SDK is loaded synchronously, so there is a slight impact to page load times.

A final point to note is that your JavaScript will contain a static copy of your feature flag rules. We do encrypt all strings in your rules, so specific user keys, e-mail addresses, and user names will not be revealed.

Front-end flags