JavaScript SDK - Advanced Setup

Read our quickstart guide to learn how to load and initialize the Facebook SDK for JavaScript. While the quickstart will use common defaults for the options available when initializing the SDK. You can customize some of these options.

Supported Browsers

The Facebook SDK for JavaScript supports the latest two versions of the most popular browsers: Chrome, Firefox, Edge, Safari (including iOS), and Internet Explorer (version 11 only).

Changing the Language

In the basic setup snippet, the en_US version of the SDK is initialized, which means that all of the Facebook-generated buttons and plugins used on your site will be in US English. (However, pop-up dialogs generated by Facebook like the Login Dialog will be in the language the person has chosen on Facebook, even if they differ from what you've selected.) You can change this language by changing the src value in the snippet. Take a look at Localization to see the different locales that can be used. For example, if your site is in Spanish, using the following code to load the SDK will cause all Social Plugins to be rendered in Spanish.

<script async defer crossorigin="anonymous" src="https://connect.facebook.net/es_LA/sdk.js"></script> 

Login Status Check

If you set status to true in the FB.init() call, the SDK will attempt to get info about the current user immediately after init. Doing this can reduce the time it takes to check for the state of a logged in user if you're using Facebook Login, but isn't useful for pages that only have social plugins on them.

You can use FB.getLoginStatus to get a person's login state. Read on for more about using Facebook Login with the JavaScript SDK.

Disabling XFBML Parsing

With xfbml set to true, the SDK will parse your page's DOM to find and initialize any social plugins that have been added using XFBML. If you're not using social plugins on the page, setting xfbml to false will improve page load times. You can find out more about this by looking at Social Plugins.

Triggering Code when the SDK loads

The function assigned to window.fbAsyncInit is run as soon as the SDK has completed loading. Any code that you want to run after the SDK is loaded should be placed within this function and after the call to FB.init. Any kind of JavaScript can be used here, but any SDK functions must be called after FB.init.

Debugging

To improve performance, the JavaScript SDK is loaded minified. You can also load a debug version of the JavaScript SDK that includes more logging and stricter argument checking as well as being non-minified. To do so, change the src value in your loading code to this:

src="https://connect.facebook.net/en_US/sdk/debug.js"

The debug version should not be used in your production environment, as its payload is larger and is worse for the performance of your page.

More Initialization Options

The reference doc for the FB.init function provides a full list of available initialization options.