ShareThis Forums » Developers

Deferred Javascript Loading?

(7 posts)

  1. Hi,

    Our Web site programming guidelines do not allow to load Javascript libraries in the <head></head> section. Our guidelines, for page loading optimization and user comfort purposes, ask to load them immediately before the closing </body> tag. Then we use an "onload" handler to run any Javascript code that must be done once the page is loaded.

    I have tried this with the ShareThis API but for some reason, when the ShareThis widget javascript code is placed outside <head></head>, a button is always rendered, even without creating a Shared Object. The widget code seems smart and detect whether it in <head></head> and does not render any button in this case...

    Is there a parameter I can pass in the widget javascript code so that no button is rendered, even if the code is outside <head></head>?

    Example of what I'd like to do:

    <html>
    <head></head>
    <script>
    function onload() {
      var obj = SHARETHIS.addEntry( ... );
      var el = document.getElementById( "mydiv" );
      obj.addButton( el );
    }
    </script>
    <body onload="onload">
    ...
    <div id="mydiv"><a href="javascript:void(0)">Share This</a></div>
    ...
    <script src="http://w.sharethis.com/widget/?tabs=web%2Cpost%2Cemail(...snip...)"></script>
    </body>
    </html>

    As is, it does not work: a button is rendered at the end of my body.

    Thanks for you help. ShareThis is a fantastic widget!

    --Mikael

    Posted 8 months ago #
  2. Hi Mikael. The button=false param was not being passed correctly from the query string to the script. This bug has been corrected in the latest release.

    Here is a boring but functional example:
    http://jayridge.googlepages.com/defer-sharethis.html

    cheers,
    Jay

    Posted 8 months ago #
  3. Thank you Jay. Your example is very clear and works well most of the time, but for some reason, once in a while, the "ShareThis" button still appear at the page bottom, even with your above URL. See screen capture at:
    http://www.shortreckonings.com/tmp/deferred-sharethis.png

    It looks like a cache issue: You may be serving the sharethis JS code from a load balancing system or via a proxy and is it possible that the old version still exists somewhere?

    The problem appears randomly. Of course I have done shift+ctrl+reloads, have closed my browser. This was observed over a period of 1 week. I would say it works fine 90% of the time.

    To exclude a browser issue on my end, I did a test from both FF and IE, as well as from other computers that did never load the above URL before, and was still able to observe the problem (randomly).

    Please advise. I don't feed confident to use button=false in production at this point.

    Also: What does the bind:false parameter does in addEntry()?

    Thanks!

    Posted 7 months ago #
  4. hassanhodges
    Member

    I started using this technique a couple months ago and it worked like a charm, until sometime overnight last night when it started blowing up the page.

    <script language="javascript" type="text/javascript">
    function deferIt(){
    var obj = SHARETHIS.addEntry({
    }, {button:true,bind:false});
    var el = document.getElementById("sharemail");
    obj.attachButton(el);
    }

    window.onload = function() {
    deferIt();
    }
    </script>

    When I remove the deferit function it works fine.

    I also see the same problem on the sample page http://jayridge.googlepages.com/defer-sharethis.html

    any ideas?

    Posted 1 month ago #
  5. It would be great to have a quality solution for this. The two WordPress sites that I have running this would barely load last night because of the sharethis script. It makes the sites look bad.

    Posted 1 month ago #
  6. If you set buttons:false that seems to make it work again. Also the 2.x version of the code has no more bind variable it seems.

    Posted 2 weeks ago #
  7. Guys,

    bind:false; is no longer supported, in the new code button:false does the same thing.
    Basically button:false would hide the button but the span for it was still being created. The bind:false would not create the span tag.

    Now button:false does not create the span tag either and we have deprecated bind:false

    Please accept my apologies if it broke some pages

    thanks,
    Manu
    manu (at) sharethis dot com

    Posted 2 weeks ago #

RSS feed for this topic

Reply

You must log in to post.