Friday, December 7, 2007

Reference external Facebook JavaScript with script tags

FBJS can now be placed into an external file and referenced using script tags, like this:


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

You point the src attribute of the script tag to (the absolute URL of) your hosted FBJS file, as you would normally do. When your Facebook application is run, this will be rendered into a Facebook URL, which points to a cached version of your FBJS file. The caching for the external file is implemented in the same way images loaded using the img tag are cached.

Previously, you could only reference external FBJS by embedding the scripts into an external FBML file, which is then loaded into your Facebook application using AJAX (with Ajax.FBML). This new feature makes it easier to refactor and maintain your client-side scripts.

Related posts on FBJS:
Lessons in FBJS
How I created a Facebook application with FBJS
Facebook releases FBJS
No JavaScript for Facebook Mobile Platform

1 comments:

Loren Koss said...

I am unable to get this to work. My LINK tags get modified, but my SCRIPT tags just get ignored in the final HTML that facebook creates. Has anyone had any success with this?