Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The inclusion via addthis is not my preferred way to include social buttons. In fact as you noticed, sometimes some errors are thrown and if the addthis library fails (e.g. javascript error, server timeout...) <strong>all</strong> buttons could fail, since they depend by a unique library. Beside, for a simple matter of performance, addthis is a script who loads other scripts (it's 33kb gzipped) so it can be avoided and I can take full control of social buttons inclusion.</p> <p>I prefer load asynchronously all the needed libraries and inject the necessary markup only if I really need them, like this</p> <pre><code>$(document).ready(function() { if (('.socialshare').length) { /* twitter button */ $('&lt;a href="https://twitter.com/share" class="twitter-share-button"&gt;Tweet&lt;/a&gt;').appendTo($('.socialshare')); loadscript('//platform.twitter.com/widgets.js', 'twitter') /* Google +1 button */ $('&lt;div class="g-plusone" data-size="medium" data-annotation="bubble" data-expandTo="top"&gt;&lt;/div&gt;').appendTo($('.socialshare')); loadscript('https://apis.google.com/js/plusone.js', 'google-plusone'); } }) </code></pre> <p>(for the sake of performance, cache a reference to <code>.socialshare</code>) <code>loadscript</code> is a simple script loader function like this</p> <pre><code>function loadscript(url, id) { var js, fjs = document.getElementsByTagName('script')[0]; if (document.getElementById(id)) { return; } js = document.createElement('script'); js.id = id; js.charset = "utf-8"; js.src = url; fjs.parentNode.insertBefore(js, fjs); }; </code></pre> <p>basically if my template contains the element with social button (the <code>.socialshare</code> element) I inject the script element with an id (so that I'm sure no other script can inject them twice)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload