lazy-fb let's you load Facebook's JS SDK lazily.
It's just a very thin (~700 bytes) layer on top of Facebook's snippet.
$ npm install --save lazy-fb
Then with a module bundler like webpack, use as you would anything else:
// using ES modules// using CommonJS modulesconst lazyFB =
The UMD build is also available on unpkg:
You can find the library on
The exported function returns a
Promise which resolves with the SDK. So you can use it with promises or async/await. The SDK will also be globally available on
window.FB. Calling the function multiple times will only load the SDK once.
const lazyFB =// Promises// async/awaitconst FB = awaitFB
On top of all the standard options for
status, etc. you can pass the following options to change what will get loaded:
lang: 'en_US' // the language of the SDKdebug: false // whether to load the debug build or notsdkModule: '' // Facebook recently separated some modules from SDK. Other values are ['xfbml.customerchat']