Friday, October 15th, 2010 | Adventures, jQuery, Web Dev, WordPress
In my work I create a lot of WordPress sites for my clients, and often times we’ll put the share links and social proof in the footer of each post. Some time ago, facebook introduced the like button for public use with iframes, which makes it very easy to incorporate just about anywhere, the only problem is that the iframes slow down the loading of the site, especially effecting things like javascript functionality, sometimes, it hangs on waiting for facebook, so instead of my content loading, I’m waiting on facebook:
![]()
I’ve been trying to come up with a solution for this. So I asked my friend Brian Morykon his thoughts. He suggested using spans instead of iframes, then when the dom was ready to replace the spans with iframes throughout, that way it would load after everything else. I tried it, and it worked. The only thing that is a little different here is that I am only using the src attribute from the spans, the other parameters I’m filling in on .replaceWith()
<div class="facebooklike"> <span class="facelike" src="http://www.facebook.com/plugins/like.php?href=<?php the_permalink(); ?>&layout=button_count&show_faces=false&width=60px&action=like&colorscheme=light&height=21"></span> </div>
jQuery("span.facelike").each(function() {
var url = jQuery(this).attr("src");
jQuery(this).replaceWith('<iframe src=' + url + ' scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60pxpx; height:21px;" allowTransparency="true" />');
});
Note: