Cart  

product (empty)

Main >> Web Development

Async Twitter buttons

Loading the Twitter Javascript API will add to the loading time of your page. You can overcome this by loading the Twitter javascript after the page loads. Twitter documentation does not provide examples for this but we can easily use the Facebook code samples for reference.

function init_tw(){
    (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 = "//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'tw-jssdk'));
}

You can call this function on page load and have the tweet buttons parsed. You can get the code for the tweet buttons from the twitter docs:

http://twitter.com/about/resources/tweetbutton

Just remove the javascript and use the code from twitter. You can event dynamically add the tweet button before calling this function.

Author: Burhan BAVKIR


Share |
You need to login to be able to comment.

HomeHome