Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi all,
I have a simple question as it seems that I'm missing something obvious. Facebook Javascript SDK requires an initial load, before you can actually use the methods within it. It is recommended to load it asynchronously:
XML
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>


The question is, do I need to call
JavaScript
FB.init()
on each page that uses the SDK, or it is enough to call 'init' once and include
HTML
<script src="//connect.facebook.net/en_US/all.js"></script>
script tag on other web pages. Thanks in advance.
Posted
Updated 4-Dec-11 0:03am
v2

1 solution

Providing the browser session isn't closed, then you should only have to call FB.init() once at the start, the rest should remain resident in memory.


If in doubt, just try it out!


(You can't do any harm after all :) )
 
Share this answer
 
Comments
Ciumac Sergiu 4-Dec-11 6:44am    
Thanks Dave.
RaviRanjanKr 4-Dec-11 6:50am    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900