FeatureLoader.js.php

From Facebook Developer Wiki

Jump to: navigation, search

FeatureLoader.js.php is the main JavaScript file that needs to be included for Facebook Connect functionality. It's a small, lightweight file that helps bootstrap the rest of the Connect library.

To use it in your own Connect site, add this script in the <body> of your page (it may write directly to the document, so including it in the <head> can be problematic):

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


You must put the FeatureLoader script before any other Facebook Connect scripts or API calls. You can put it after any XFBML in the page, but the XFBML won't get rendered until the FeatureLoader script runs.

It can also be used on Facebook for iframe applications. If you are using an iframe application, we suggest you include it like this (without the .connect in the URL). It's the same file, but this one is loaded from a different tier.

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


Important! You need to reference the Feature Loader only once on a given Web page. For example, if you have a Facebook Connect site, and then add a social widget like the Fan Box to your site at a later time, you should not reference the Feature Loader again.

FeatureLoader and the Connect JavaScript Package

Facebook's ability to push out changes (for bug fixes or feature enhancements) is limited by the cache timeout in client browsers. If we cache files for 30 days, then any changes would take 30 days to propagate. Also, such propagation would be non-deterministic, and if the client is running an out-of-date JavaScript file in their cache, then it can cause various problems when those files try to interact with Facebook servers. So we need to run the core include file (FeatureLoader.js.php) with a short cache timeout. Currently it's one hour for FeatureLoader.

However, if the client has to reload the JavaScript include once an hour, then it has to be fast. We don't want you to have to reload the entire JavaScript Client Library every time, since that wastes bandwidth. Instead, we put most of the functionality in a separate package, the Connect JavaScript package (http://static.ak.fbcdn.net/rsrc.php/version/js/connect.js.pkg.php -- currently version 0.4), which contains the rest of the functionality necessary to power Connect. It also has a really long cache timeout and is essentially immutable. Then FeatureLoader contains a reference to the package.

That way, clients will re-fetch the small FeatureLoader every hour, but will only re-fetch the Connect library whenever Facebook pushes out changes to it. Typically, the library is updated once a week, and the updates are usually announced on the Platform Status Feed.

Here's a summary of the two files:

File Size Cache Timeout Functionality URL
FeatureLoader.js.php <2k 1 hour basic interface and bootstrap functions always the same
connect.js.pkg.php ~48k 30 days everything else contains a version


Rendering Facebook Connect in Other Languages

If you have a Facebook Connect site and your content is in another language, you can have the Facebook Connect features (like the Connect dialog box, permission dialogs, and Feed forms) appear in the same language to provide your users with a seamless experience.

All you need to do is append the locale of your choice to the FeatureLoader.js.php script. For example, if your site is written in Spanish for a Latin American audience, you could choose to have Facebook Connect features appear in Spanish like this:

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

Do this wherever you reference the FeatureLoader script. Otherwise, Facebook Connect defaults to the en_US (English/United States) locale.

reference