FB RequireFeatures

From Facebook Developer Wiki

Jump to: navigation, search

FB_RequireFeatures is a method for dynamically loading JavaScript components. It is defined in FeatureLoader.js.php.

Contents

[edit] Usage

In most Facebook Connect sites, you won't need to call RequireFeatures at all; it will be called for you within this API call:

FB.init(API_KEY, "xd_receiver.htm");


However, if you are particularly performance-sensitive, or you are using Facebook Connect on only a small part of your site (for example, just to display a Feed form), then you may want to only load the Facebook JavaScript libraries at the time you need them.

You will always write a script include for FeatureLoader.js.php within your main page. This file is small and shouldn't affect your latency.

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>


Then, when the time comes to actually make use of the Facebook functionality, you can wrap your functions in FB_RequireFeatures. This loads the necessary libraries, and then executes your function. You will also need to call FB.init once the libraries are loaded.

For instance, this code could be used as an onclick handler for a Facebook Connect login button:

function facebook_button_onclick() { FB_RequireFeatures(["Connect"], function() { FB.init("API_KEY", "xd_receiver.htm"); FB.Connect.requireSession(); }); }


You can also use this to raise a Feed form:

function show_feed_dialog() { FB_RequireFeatures(["CanvasUtil"], function() { FB.init("API_KEY", "xd_receiver.htm"); FB.Connect.showFeedDialog(TEMPLATE_ID, {article_id : "Article"}); }); }

[edit] Features

Here are all the features you can use with FB_RequireFeatures. Items in black are the most commonly used.

Image:Require_features.jpg


[edit] Feature Definitions

The Facebook Connect JavaScript Library comprises a list of features. The available features include:

Api
Allows for making API calls to Facebook from JavaScript.
Base
Basic core functions, like bootloads
CanvasUtil (dependencies => "Common", "XdComm")
Displays inline iframe lightboxes, including Feed forms. Supports dynamic resizing of iframes and other utilities specific to iframe-based Facebook applications.
Common (dependencies => "Base")
Code common to all features, utility functions
Connect (dependencies => "CanvasUtil", "Api")
Allows for all Facebook Connect login functionality.
XdComm (dependencies => "Base", "Common")
Cross-domain communications library; allows for cross domain communication.
XFBML (dependencies" => "CanvasUtil", "Api", "Connect")
XFBML support (all classes in FB.XFBML namespace); this feature depends on Facebook Connect, and also allows for drawing of XFBML elements.

[edit] See Also

reference