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:
The “src” attribute in FBML is only enabled for canvas page at this time.
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.
Please make sure that you don’t use a different script url per user. For example,
should never be used.
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.
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.
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.