0

I'm using the Recommendations plug on my site and it's really slow to load, mostly with Firefox.

I find most FB plugins seem to have this problem. Is it due to the iFrame they create, there seems to be a lot of data being created by the plugin.

Would it be better to make my own JS verson?

If so, does anyone have any pointers to access the same data via an FQL/AJAX call?

Following comments below, I thought I'd explain exactly what I'm doing, I'm loading the plugins dynamically using the script below. Currently only displaying the recommendations plugin, but eventually all those mentioned will be included.

HOWEVER... I've noticed this problem even when directly injecting the plugin to a page.

$(document).ready(function () { addFBelements(); });

 //==== THIS GENERATES SOCIAL ELEMENTS ====
 function addFBelements() {
     window.fbAsyncInit = function () { // sets up asynchronous loading of FB elements
         FB.init({ // initialise FB
             appId: 'MYAPPID',
             status: true, // check login status
             cookie: true, // enable cookies to allow the server to access the session
             xfbml: true,  // parse XFBML
             oauth: true
         });
     };

     (function () {
         if ($("#fb-root").length <= 0) {
             $('body').prepend('<div id="fb-root"></div>'); // add FB div to top of page if not already there
         };
         var e = document.createElement('script'); // load the Facebook Javascript file
         e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
         e.async = true;
         document.getElementById('fb-root').appendChild(e);
         $.getScript(document.location.protocol + '//apis.google.com/js/plusone.js'); // Load Google Plus files
         $.getScript(document.location.protocol + '//platform.twitter.com/widgets.js'); // load Twitter files
         renderButtons(); // render the buttons in the page
     } ());
 };
 // ends setting up of FB/Twitter etc links and JS files

 // add Social elements to the pages where required with correct sharing URLs
 function renderButtons() {
     var linkUrl = window.location.href;

     if ($('.googlePlus').length > 0) {
         $('.googlePlus').html('<g:plusone href="' + linkUrl + '" size="medium" style="float:right"></g:plusone>');
     };
     if ($('.fbLike').length > 0) {
         $('.fbLike').html('<fb:like send="false" href="' + linkUrl + '" layout="button_count" width="80" show_faces="false" font="arial"></fb:like>');
     };
     if ($('.fbSend').length > 0) {
         $('.fbSend').html('<fb:like send="false" href="' + linkUrl + '" layout="button_count" width="80" show_faces="false" font="arial"></fb:like>');
     };
     if ($('.tweet').length > 0) {
         $('.tweet').html('<a href="http://twitter.com/share" data-url="' + linkUrl + '" class="twitter-share-button" data-count="none" data-via="hartnollguitars">Tweet</a></span>')
     };
     if ($('.fbComments').length > 0) {
         $('.fbComments').html('<fb:comments href="' + linkUrl + '" num_posts="3" width="640"></fb:comments>');
     };
     if ($('.fbRecommend').length > 0) {
         $('.fbRecommend').html('<img style="border: none" alt="" src="images/like_us_home.png"><fb:activity recommendations="true" border_color="#000000" font="arial" colorscheme="dark" header="false" height="400" width="220" site="www.hartnollguitars.co.uk"><span>');
     };

 };
 // == END OF SETTING UP SOCIAL NETWORKING ELEMENTS. ====

You can see that script sets up all my FB/Twitter etc elements and inserts them into elements with the respective classes where present.

The appId element is not required for the purposes in question, but I also have an Events secton which shows my FB events and FB login, for both I need the appId for validation.

(just trying to explain that whilst it's bulky for just displaying recommendations, it is intended to do a lot more!)

Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97
  • Most of Facebook social plugins are actually blazing fast if used appropriately (not too many on page, and even for many plugins on page the only real issue is page loading time). Are you sure that this is exactly what slowing the browser down? – Juicy Scripter Mar 19 '12 at 20:13
  • Pretty sure, watching the 'net' console in Firefox, everything else is loaded and this FB recommendation script is still churning away. This is the only thing on the page at the moment. The other thing I noticed is that it seems to actually be loading twice. I have created a script which loads all this stuff, I'll add it to my question,maybe it's my fault... that said though, I have had this problem several times! – Jamie Hartnoll Mar 19 '12 at 20:18
  • @JuicyScripter I've added my entire code, can you tell me if that would cause FB Recommendations to load twice? – Jamie Hartnoll Mar 19 '12 at 20:25

1 Answers1

0

Please don't put window.fbAsyncInit = function () { inside of jQuery's $(document).ready(function () { as it will cause mixed results in different browsers under different conditions. See my recent answer here:

http://facebook.stackoverflow.com/questions/9788273/fblogin-button-not-showing-up-in-firefox-ie-or-opera-but-works-fine-in-chro/9792371#9792371

I've also seen issues with $('.googlePlus').html('<g:plusone in IE8. See: Adding a Google +1 Button after page load in IE 8

Community
  • 1
  • 1
DMCS
  • 31,720
  • 14
  • 71
  • 104
  • Interesting. I've never seen it not load, but I'll certainly heed your advice there. Any idea on the apparent double loading of the recommendations scripts? Maybe related? I'm not sure, the recommendations scripts should only load when the tag is loaded? – Jamie Hartnoll Mar 21 '12 at 08:42
  • That's pretty easy to determine. Just strip out ALL javascript from your page and start adding in a little by little until it loads once, then little by little until it loads twice. That should tell you where the problem lies. – DMCS Mar 21 '12 at 12:47
  • OK, just back tracking one point. I've taken the `window.fbAsyncInit` bit from `$(document).ready(` but now I can't get the buttons to actually render. Presumably this is because the elements with the required classes that I'm expecting the buttons to be displayed in are not loaded until the document is fully loaded. How can I trigger a function to load once the document is fully loaded AND the `fbAsyncInit` function has fully loaded without putting it all in `$(document).ready(`? – Jamie Hartnoll Mar 21 '12 at 13:09
  • put your jQuery ready function (just the relevant parts) inside of the fbAsyncInit – DMCS Mar 21 '12 at 13:17