All social plugins in this module (facebook, twitter, google plus, and linked-in) have a certain way to load the javascript asynchronously. According to common belief, loading javascript asynchronously should help to decrease page load time.

If I look into the code of this module, currently there is no option to load javascript asynchronously. I'm sure the author of this plugin has some reasons for this decision.

But, I think it should be nice if there is an option to use asynchronous version of javascript instead of synchronous one.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lnunesbr’s picture

Status: Active » Postponed

ganagus, thanks for asking... actually, there is already a thread for that #1447522 that considers the implementation of Socialite.js for a more 'softly' loading of the widgets... please, keep an eye on there...

angrytoast’s picture

Version: 7.x-2.8 » 7.x-2.10
Category: support » feature
Status: Postponed » Needs review
FileSize
2.97 KB

Following up on the issue, but there appears to be little progress on the socialite integration at https://drupal.org/node/1447522.

So, I came up with a patch.

Proposed Solution:

An async solution if the library is set to external (any third party libraries), using an async loading pattern for all external libraries. I don't see a reason to include libraries scripts in a non-async pattern, but would be glad to hear about why there should be such an option.

patch attached:

fearlsgroove’s picture

This patch works great and mitigates a really impactful downside to social plugins. I'd love to see this commited while waiting for progress on the Socialite.js approach.

claes nilsson’s picture

I would really like to see this feature in the 6x version if possible

angrytoast’s picture

Realized the previous patch has a dumb loop placement which just happened to work. But here's an updated one, and also includes offloading the facebook script to the external loaded script set. The Facebook change isn't completely necessary, but does allow for moving the script loading to after window onload event.

On that note, also changed the logic to grabbing the externals on window load rather than DOM ready, may be set this as a admin option? Thoughts?

fearlsgroove’s picture

It's going to need to be on dom ready to ensure widgets that rely on markup to replace have their needed markup already loaded.

fearlsgroove’s picture

Apparently that version will also duplicate the externals references due to the way drupal_add_js works with settings. Here's a version that stores the externals and applies via a page_alter hook (probably requires a cache clear due to new hook)

fearlsgroove’s picture

Version: 7.x-2.10 » 7.x-2.x-dev
FileSize
5.58 KB

Erp whitespace error

wiifm’s picture

Status: Needs review » Reviewed & tested by the community

Code looks nice, have tested with Google and Twitter, both work well. Was unable to test the facebook loading due to the fact that we use the iframe version.

This is a massive improvement. +1 from me.

chr.fritsch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
FileSize
7.16 KB

Patch against current version

rt2sd’s picture

I would love to see this merged in an official release.
We should all care about async loading because it does affect page loading time and therefore SEO.

I can sponsor a bit if it helps.

TheLioness22’s picture

I came across this issue queue after looking for an "asynchronous mode" checkbox in the easy_social settings (which wasn't there). I will try out the patch, if I can figure out how to apply it. I hope to see this functionality rolled into the main release. Personally, I think asynchronous load should be enabled by default (for any social buttons that support it), and need to be disabled to use the other. Some may disagree, however. Regardless, I think both options should be available in the module for any social buttons that support asynchronous load.

sja1’s picture

Patch 10 is working for me.

klidifia’s picture

Status: Needs review » Reviewed & tested by the community

10 fine -- So the difference between 8 and 10 is basically just coding standards, no functionality change, so RTBC as per #9.

rhormens’s picture

Hi guys,

Error applying path, please fix

Checking patch easy_social.module...
Hunk #1 succeeded at 752 (offset 16 lines).
Hunk #2 succeeded at 765 (offset 16 lines).
Hunk #3 succeeded at 804 (offset 16 lines).
Checking patch includes/easy_social.widgets.inc...
Hunk #1 succeeded at 36 (offset 1 line).
error: while searching for:
    $font = '';
  }

  if ($facebook_type !== 'iframe') {
    // This is done here instead of using the proper hook method because the
    // script is only added in the HTMl5 and XFBML versions, not iframe.
    $script = <<<JS
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/{$lang}/all.js#xfbml=1&appId={$appid}";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
JS;
    drupal_add_js($script, 'inline');
  }

  if ($facebook_type === 'html5') {
    $markup = <<<FB
<div class="fb-like" data-href="{$url}" data-send="{$send_button}" data-layout="{$type_box}" data-width="{$width}" data-show-faces="{$show_faces}" data-action="{$action}" data-colorscheme="{$color_scheme}" data-font="{$font}"></div>

error: patch failed: includes/easy_social.widgets.inc:45
error: includes/easy_social.widgets.inc: patch does not apply
Checking patch js/easy_social_async_lib.js...

Please fix in branch 7.x-2.x.

Thanks
rhormens

rhormens’s picture

Status: Reviewed & tested by the community » Needs work
Donit’s picture

True, patch needs a rework. Subscribe.