Include files
From Facebook Developer Wiki
You can reference FBJS scripts using the src attribute of the <script> tag and the href attribute on <link> tags on canvas pages. This feature is useful for referencing large FBJS and CSS 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:
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 are some general guidelines for using this feature:
-
TheDefinitely works for Publisher too, and possibly other locations.srcattribute in FBML is enabled only for canvas pages at this time. - Please limit the total number of unique scripts for your application (across all canvas pages) to less than 1000. Facebook may start deleting old scripts if your application uses more than 1000 scripts.
- Please make sure that you don't use a different script URL for each user. For example, http://foo.com/bar.js?user_id=11 and http://foo.com/bar.js?user_id=22 should never be used.
- Since the cache policy is set to never expire, you should update the URL 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. - The URL you use to reference the included file must include your server's name; it cannot be a relative path such as '/myfolder/my.css'.
Important: After being rendered by Facebook, your external file will likely increase in size. If the rendered version (not your original!) exceeds 64KB it will not be served. You must either reduce the size or split it into separate files.
[edit] Stylesheet Includes
Stylesheet includes are cached automatically by Facebook. Just include a <link rel="stylesheet"> tag like:
Increment the version number upon each change to your style sheet, as specified above.
[edit] Tips
DO NOT EVER append a time stamp on FBML css/js. Doing so will significant increase latency and cost to both Facebook and your servers. It can also cause all of your css/js requests to be blocked when the number of unique url requests exceed a limit.
Bad Tip
A good parameter to append to the query string is the file modification timestamp. This can be accomplished automatically in php so that you do not have to update your files when the JavaScript or CSS changes.
