Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Blog
    • 2013
    • 2012
    • 2011
    • 2010
    • 2009
    • 2008
    • 2007
    • 2006
  • Developer Roadmap
  • Developer Events

Developer Blog

Wei Zhu

Support for external FBJS reference in FBML

By Wei Zhu - Thursday, December 6, 2007 at 1:29pm

We added a new feature to enable referencing FBJS scripts using the “src” attribute of <script> tag on a Canvas page. This feature is useful for referencing large FBJS scripts that can be cached on user’s browsers.

 

In order to use this feature, you just need to use regular <script> syntax in HTML. Here is an example:

<script src=”http://foo.com/bar.js” ></script>

 

When this FBML is rendered into HTML, the src attribute will be changed to point to a Facebook url that contains a cached FBJS script of the original url. In addition, the browser caching of this url is set to never expire so that client browser will cache it as well.

 

Here is some general guideline when using this feature:

  1. The “src” attribute in FBML is only enabled for canvas page at this time.
  2. Please limit the total number of unique scripts for your app (across all canvas pages) to less than 1000. Facebook may start deleting old scripts if your app uses more than 1000 scripts.
  3. Please make sure that you don’t use a different script url per user. For example, http://foo.com/bar.js?user_id=11 and http://foo.com/bar.js?user_id=22 should never be used.
  4. Since the cache policy is set to never expire, you should update the url if and only if the content of the script changes. For example, you can change http://foo.com/bar.js?v=1.0 to http://foo.com/bar.js?v=2.0 or http://foo.com/v1.0/bar.js to http://foo.com/v2.0/bar.js when a new version of the script is available.
  5. To reduce the number of HTTP requests per page (at least for the first page load) and improve performance, we recommend that you limit your FBJS script references to no more than 10 per page.
  6. If your script code is small (say a few lines), it’s probably better to embed it inline instead of using “src”.

This feature is currently in Beta, and we’d love to get your feedback and suggestions to help us improve.

 

Happy coding!

Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy