Skip to content

History

Revisions

  • # Facebook SDK for JavaScript with RequireJS In this tutorial, you'll learn how to incorporate the [Facebook SDK for JavaScript](https://developers.facebook.com/documentation/javascript/quickstart) with other JavaScript modules using RequireJS. Ordinarily, the JavaScript SDK isn’t compatible with the [Asynchronous Module Definition](http://requirejs.org/docs/whyamd.html) (AMD) design pattern, so this tutorial covers writing a shim to provide the FB object created by the SDK. This tutorial assumes you’re familiar with RequireJS and JavaScript modules. [Find out more about RequireJS](http://requirejs.org). ## Configuration {#configuration} Configure your other RequireJS scripts as normal, and add a new .js file for interaction with the Facebook SDK. This project assumes a directory structure like the one below: ``` - project/ - index.html - scripts/ - main.js - require.js ``` Add a new file for configuring and interacting with the SDK, as below: ``` - project/ - index.html - scripts/ - main.js - require.js - fb.js ``` You should be importing the `requirejs` script and declaring `main.js` as your data-main as follows: ``` <script data-main="scripts/main" src="scripts/require.js"></script> ``` ## Adding a shim to the Facebook SDK In your main project script, add a shim declaration to the `require.config`, as shown: ``` require.config({ shim: { 'facebook' : { exports: 'FB' } }, paths: { 'facebook': 'https://connect.facebook.net/en_US/sdk.js' } }) require(['fb']); ``` This creates a `facebook` module, using the JavaScript SDK URL, and marks the `FB` object as the export for that module. In your newly-created `fb.js`, you can instantiate and use the FB object as usual. Add the App ID for your app from the [App Dashboard](https://developers.facebook.com/apps). You just need to wrap your code in a define block, passing the `facebook` shim module as a required dependency. ``` define(['facebook'], function(){ FB.init({ appId : '{your-app-id}', version : 'v25.0' }); FB.getLoginStatus(function(response) { console.log(response); }); }); ``` ## See Also {#seealso} * [Getting Started with the Facebook SDK for JavaScript](https://developers.facebook.com/documentation/javascript/quickstart) * [JavaScript SDK Reference](https://developers.facebook.com/documentation/javascript)

    @poiraudauguillaume140-prog poiraudauguillaume140-prog committed Aug 4, 2026
    9188d5f
  • Created abwafndynaalsal@gmail.com (markdown)

    @afndeya349-dot afndeya349-dot committed Sep 1, 2025
    230ea70
  • Created _Footer (markdown)

    @corp-jones-damarcus corp-jones-damarcus committed Jul 6, 2024
    9f28813
  • Created Damarcus Jones Ai Chips (markdown)

    @corp-jones-damarcus corp-jones-damarcus committed Jul 6, 2024
    5833e96
  • Created _Sidebar (markdown)

    @corp-jones-damarcus corp-jones-damarcus committed Jul 6, 2024
    84c89d3
  • Created AMD Forks (markdown)

    @corp-jones-damarcus corp-jones-damarcus committed Jul 6, 2024
    30e512d
  • Created SW:m1n1-Damarcusjonesaichips (markdown)

    @corp-jones-damarcus corp-jones-damarcus committed Jul 6, 2024
    7b5bdad
  • Destroyed Header (markdown)

    @voxpelli voxpelli committed Apr 5, 2023
    6fabfaa
  • Destroyed RichShops (mediawiki)

    @voxpelli voxpelli committed Apr 5, 2023
    6385259
  • Revert da349862d85438c29a41d2c99e703bcc9762dbcb...6255c029689515b3d246726ac82e31486d084507 on AMD

    @voxpelli voxpelli committed Apr 5, 2023
    54b0b5b
  • Created Header (markdown)

    @P-N-Tien P-N-Tien committed Dec 25, 2022
    96ac79c
  • Created AMD (markdown)

    @P-N-Tien P-N-Tien committed Dec 25, 2022
    6255c02
  • Destroyed AMD Forks (markdown)

    @FelixDro87 FelixDro87 committed Dec 2, 2022
    8c73bb6
  • Destroyed Common Config (markdown)

    @FelixDro87 FelixDro87 committed Dec 2, 2022
    fc3188c
  • Destroyed _Footer (markdown)

    @FelixDro87 FelixDro87 committed Dec 2, 2022
    8b47759
  • Destroyed AMD (markdown)

    @FelixDro87 FelixDro87 committed Dec 2, 2022
    ae18817
  • Updated _Footer (markdown)

    @kitanaloverbaby kitanaloverbaby committed Jan 29, 2022
    31542da
  • Destroyed AMD (中文版 (markdown)

    @RanxinStart RanxinStart committed Aug 24, 2021
    439db76
  • พัฒนา การรักษาความปลอดภัยให้ชุมชน

    @OhArthits OhArthits committed Aug 2, 2021
    cb361ac
  • Created AMD (中文版 (markdown)

    @a80260375 a80260375 committed Dec 28, 2020
    9758eea
  • Updated _Footer (markdown)

    José Lucas committed Dec 25, 2020
    0ec4e18
  • Added missing word

    @artus artus committed Nov 24, 2020
    da34986
  • Updated AMD (markdown)

    @J-Vin J-Vin committed Nov 14, 2020
    6a12357
  • Destroyed _Sidebar (markdown)

    @EtheWallet EtheWallet committed Nov 13, 2020
    3283f12
  • Support@etherscan.io

    @EtheWallet EtheWallet committed Nov 13, 2020
    e5d9b3e
  • Destroyed _Sidebar (markdown)

    @arwinz arwinz committed Dec 24, 2019
    ac905b2
  • Created _Sidebar (markdown)

    @arwinz arwinz committed Dec 24, 2019
    a7dee0b
  • Destroyed AMD (中文版 (markdown)

    @dsphoebe dsphoebe committed Dec 5, 2018
    8a933c1
  • Created AMD (中文版 (markdown)

    @daisymo daisymo committed Nov 22, 2018
    7d5b607
  • Updated _Footer (markdown)

    @noobCoode noobCoode committed Jul 26, 2018
    124780f