Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter button script loaded synchronously, need to load it asynchronously

I having little trouble with twitter button script, which is blocking the page rendering.

The script I have been using is the following

<a href="https://twitter.com/share" class="twitter-share-button" data-url="$info['referring_url']" data-count="vertical" data-via="MyTwitterID">Tweet</a>
<script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Any ides on how to get this one sorted?

like image 471
AlexB Avatar asked Jul 21 '13 12:07

AlexB


1 Answers

Actually, I have found the way myself,

for those whom might need to know, simply add the following:

js.async=true;

so the line should look like this:

<a href="https://twitter.com/share" class="twitter-share-button" data-url="$info['referring_url']" data-count="vertical" data-via="MyTwitterID">Tweet</a>
<script type="text/javascript">!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id)){
    js=d.createElement(s);js.id=id;js.async=true;
    js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);
}
}(document,"script","twitter-wjs");</script>
like image 112
AlexB Avatar answered Oct 20 '22 23:10

AlexB