開発者向けニュースに戻る

Support for external FBJS reference in FBML

2007年12月6日作成者:Wei Zhu

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.

<p class="MsoNormal" style="margin: 0in 0in 0pt">
    <?xml namespace="" ns="urn:schemas-microsoft-com:office:office" prefix="o" ?>
    <o:p>&amp;nbsp;</o:p>
</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    In order to use this feature, you just need to use regular &amp;lt;script&amp;gt; syntax
    in HTML. Here is an example:<o:p></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    &amp;lt;script src="http://foo.com/bar.js" &amp;gt;&amp;lt;/script&amp;gt;</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    <o:p>&amp;nbsp;</o:p>
</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    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.</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    <o:p>&amp;nbsp;</o:p>
</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    Here is some general guideline when using this feature:</p>
<ol start="1" style="margin-top: 0in" type="1">
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        The "src" attribute in FBML is only enabled for canvas page at this time.</li>
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        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.</li>
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        Please make sure that you don't use a different script url per user. For example,
        <a href="http://foo.com/bar.js?user_id=11">http://foo.com/bar.js?user_id=11</a>
        and <a href="http://foo.com/bar.js?user_id=22">http://foo.com/bar.js?user_id=22</a>
        should never be used.</li>
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        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 <a href="http://foo.com/bar.js?v=1.0">
            http://foo.com/bar.js?v=1.0</a> to <a href="http://foo.com/bar.js?v=2.0">http://foo.com/bar.js?v=2.0</a>
        or <a href="http://foo.com/v1.0/bar.js">http://foo.com/v1.0/bar.js</a> to <a href="http://foo.com/v2.0/bar.js">
            http://foo.com/v2.0/bar.js</a> when a new version of the script is available.</li>
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        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.</li>
    <li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">
        If your script code is small (say a few lines), it's probably better to embed it
        inline instead of using "src".</li>
</ol>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    This feature is currently in Beta, and we'd love to get your feedback and suggestions
    to help us improve.</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    <o:p>&amp;nbsp;</o:p>
</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt">
    Happy coding!</p>

タグ: