Thursday, April 19, 2012

Wait to untill page is ready to load all social media buttons

Currently i have this 'widget' to provide all this social media buttons to share the page,



This is the code:



    <div class="social_media social_media_button">
<div class="smCnt fbCnt">
<div class="fb-like" data-href="http://funcook.com/" data-send="true" data-layout="button_count" data-width="200" data-show-faces="false" data-font="verdana"></div>
</div>
<div class="smCnt gpCnt">
<g:plusone size="medium"></g:plusone>
</div>
<div class="smCnt ptCnt">
<a href="http://pinterest.com/pin/create/button/?url=http://funcook.com/'" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
</div>
<div class="smCnt twCnt">
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="es" >Twittear</a>
</div>
<div class="smCnt tmCnt">
<a href="http://www.tumblr.com/share" title="Share on Tumblr" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:81px; height:20px; background:url('http://platform.tumblr.com/v1/share_1.png') top left no-repeat transparent;">Share on Tumblr</a>
</div>

</div>
<script>!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>
<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
<script type="text/javascript">
window.___gcfg = {lang: 'es'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<script>(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 = "//connect.facebook.net/es_LA/all.js#xfbml=1&appId=121495767915738";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


Wich works as expected but few resources are loaded during the page load, so i tried:



<script>
/* just include them in a $document.ready */
$(document).ready(function(){
!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");
window.___gcfg = {lang: 'es'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
(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 = "//connect.facebook.net/es_LA/all.js#xfbml=1&appId=121495767915738";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'http://assets.pinterest.com/js/pinit.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
$('.social_media').slideDown();
})

</script>


Wich also seems to work, but still seeing this items on the page load report:



http://tools.pingdom.com/fpt/#!/wZNCkPIsf/http://funcook.com/



How can i make sure this buttons won't affect the (initial) load time?





No comments:

Post a Comment