Forum Moderators: Robert Charlton & goodroi
<!-- google+1 --><script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <g:plusone size="medium" count="false"></g:plusone> /* Enable Cache */
$.ajaxSetup({ cache: true });
/* Facebook */
window.fbAsyncInit=function(){FB.init({appId:'999999999999',status:false,cookie:false,logging:false,xfbml:true, channelUrl:'http://www.example.com/channel.html'});};
$(document).ready(function(){
setTimeout(function(){
$.getScript("http://connect.facebook.net/en_US/all.js");
$.getScript("http://platform.twitter.com/widgets.js");
$.getScript("http://platform.linkedin.com/in.js");
$.getScript("http://apis.google.com/js/plusone.js");
},100);
});
Within a week of after adding +1 buttons, all Google referrals to the news pages has slowed to a trickle (5-10 a day)
You can use Jquery/getScript (or other alternatives) to load scripts after document.ready. +1 and twitter works out of the box, for Facebook, just use window.fbAsyncInit function..
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
status : true,
cookie : true,
xfbml : true,
channelUrl : 'custom channel url'
});
...
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
For those of you who have already implemented the button, you’ll need to update the code to the new async snippet, and then you should see an overall improvement in your page load time.
First, we’ve begun to roll out out a set of changes that will make the button render up to 3x faster on your site. No action is required on your part, so just sit back, relax, and watch as the button loads more quickly than before.
In addition to the improvements made to the button, we’re also introducing a new asynchronous snippet, allowing you to make the +1 experience even faster.... For those of you who have already implemented the button, you’ll need to update the code to the new async snippet, and then you should see an overall improvement in your page load time....
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'http://platform.twitter.com/widgets.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
[edited by: Robert_Charlton at 6:06 pm (utc) on Aug 10, 2011]
[edit reason] added topic of new thread [/edit]
var likecode='<fb:like href="http://www.facebook.com/" send="false" layout="button_count" width="90" show_faces="false" font="arial"></fb:like>';
var tweetcode='<a href="http://twitter.com/" class="twitter-follow-button" data-button="grey" data-text-color="#FFFFFF" data-link-color="#FFFFFF" data-width="225px">Follow @</a>';
var pluscode='<g:plusone size="medium"></g:plusone>';
$('#likediv').append(likecode);
$('#tweetdiv').append(tweetcode);
$('#plusdiv').append(pluscode);
<script type="text/javascript">
(function(){
jqhead=document.getElementsByTagName('head')[0];
var jqscript=document.createElement('script');
jqscript.type='text/javascript';
jqscript.async=true;
jqscript.src='yourscript.js';
jqhead.appendChild(jqscript);
})();
</script>