Engineering Tips

From Facebook Developer Wiki

Jump to: navigation, search

Contents

Facebook Platform Best Practices: Engineering Tips

You can find technical documentation and resources at the Facebook Developers Site and on this wiki, which may also be helpful during the conceptualization and design phases of your product. Once you begin engineering, these tips may be helpful for you.

Setting Up Your Application

See Setting up to Build for information on obtaining developer keys and setting up your application. In your application setup, you'll need to define two important URLs: your frame URL ('your_app' would mean users access your canvas pages through apps.facebook.com/your_app/…) and your callback URL, which specifies where requests to these frame URL pages go on your outside server. If you are designing a desktop application, there is no callback URL necessary.

Running Your Server

The origin of all API calls, as well as the source of canvas FBML, is your server or set of servers. There is no technical contract between Facebook and your server, other than the GET, POST, FBML, or XML data transferred, so any functional combination of operating system, web server, execution language and database system works.

Many applications are very data-heavy. If it’s appropriate (that is, if your data changes infrequently compared to the number of calls to read it), consider using a caching layer to ease the load on your databases. Facebook maintains the open-source memcached branch, an extremely simple in-memory LRU cache that takes load off our databases.

Specific Technical Offerings

Investigate wiki.developers.facebook.com for the wide range of functionality FBML makes available. Some noteworthy features of FBML and our general architecture include:

Images

When an image is provided to Facebook by an <img> tag, Facebook will cache that image in its own CDN for faster serving. This also prevents malicious applications from determining the IP address of the viewing user.

Media Content

We provide several FBML tags for dealing with some of the most common web application data. Specifically, we are able to embed the following types of media through FBML tags:

  • flv (streaming media)
  • swf (Shockwave Flash)
  • MP3
  • Silverlight

FBJS and Mock AJAX

In general, Facebook does not allow arbitrary JavaScript to execute, as it is inherently unsafe. However, we’ve made our FBJS language available, which allows most general, safe kinds of JavaScript interaction, as well as access to parts of the DOM tree.

We also provide a facility called Mock AJAX that wraps AJAX calls back to your server, without requiring you to run arbitrary JavaScript. This will allow you to accomplish what you normally could with AJAX, in a safer but slightly more circuitous way. FBML makes this available through simple tags.

iframes

You may embed an iframe within a canvas page. If the functionality provided by FBJS and Mock Ajax are insufficient for your needs, you can use an iframe to execute whatever you want within that frame.

Note, however, that you will lose the capability of FBML within this frame, as it does not run on our servers, and since you are not easily able to interface between the contained element (iframe) and the container (canvas). In some cases, using an iframe for part of the page may serve as the best solution.


Building for Performance

In addition to designing your own server for good performance, thoughtful use of our technologies can create a faster experience for your users, and a more manageable task for your servers.

fb:ref

The fb:ref FBML tag can be published to a large number of (or all) user application profile boxes, for content that is updated identically for each. In this way, you can avoid making millions of profile update calls when something of this nature changes. Also, using fb:ref on the canvas for static content can increase performance.

FQL

Our FQL grammar shares a syntax with the popular SQL, running SELECT commands on our dataset as a relational table rather than requiring direct use of the APIs in some cases. The API and FQL methods are generally equivalent, unless you expect to pull down much more data than you will use from an API call and are able to do limiting statements on our servers through FQL. This can save you many CPU cycles, and some bandwidth in transit. FQL does nested SELECT execution but not JOIN, nor any mutating operation (INSERT, UPDATE, REPLACE … ).

friends.get

Since the friends.get call remains so central to building good social applications, we can return this at the beginning of a user’s canvas request, to avoid an extra round-trip between our servers.

Using Available Resources

Facebook offers several resources to help you develop your applications.

You can also read the Facebook Developers News Feed for the latest news on upcoming features and events, and the Facebook Platform Status Feed for the current status of Facebook Platform.

reference