If you’re using the TweetMeme Retweet Button on your blog or website, and you’ve noticed it’s been slowing down your page load times, then this article is for you. I will discuss two common ways to install the Retweet Button–through the WordPress plugin and through adding a custom <script> element to your HTML code–and I will explain why these two implementation methods are probably preventing your web pages from loading as quickly as they could be. Then I will show you how to install the TweetMeme Retweet Button in a way that doesn’t affect your page speed. My solution is not limited to the TweetMeme button, so a reasonably-intelligent person can apply these same steps to any iframe-based social media smart buttons.
Most bloggers use social media networks and micro-blogging sites like Twitter to promote their content. One of the easiest ways to do that is to install social media widgets on your blog and hope that your readers are grateful enough to share your content with their friends. I mean…it’s the least they can do, considering how many hours of your personal time you put into your blog posts. *ahem* Right?
The problem with some of these “smart” social media widgets (i.e., the ones that display a number of votes, diggs, sphinns, etc.) is that they usually require your page to make several HTTP requests for external files. Due to the way these widgets are normally installed, your page can’t finish loading until all of these requests have been answered. Ultimately, it doesn’t do you much good to put these things on your blog, if the result is a sluggish website that drives your readers away.
One social media widget that has become very popular is the retweet button from TweetMeme.com. For most of you, it looks something like this:
When you write super-amazing content like I do, your TweetMeme buttons tend to look more like this:
But the purpose of today’s article is to show you how to prevent your retweet buttons from ending up like this:
As soon as you realize my animated .gif isn’t actually going to load anything, we can continue…
To fully understand the solution I propose in this article, you should probably read the next two sections, which explain why the WordPress plugin sucks…and why the customized <script> option sucks. However, you’re more than welcome to skip straight to the solution↓.
Why does the TweetMeme WordPress plugin suck?
The TweetMeme Retweet Button plugin for WordPress has a couple of useful features, but ironically, inserting the Retweet Button code into your posts is not one of them. The features you might consider using are the TweetMeme Analytics interface, the option to automatically ping TweetMeme.com when you post new content, and the option to insert the Retweet button into your RSS feed pages. Unfortunately, the code that the WordPress plugin writes into your HTML source code is NOT usable for what we need to do. Therefore, if you keep the plugin activated, be sure to go to the TweetMeme settings and change the Position option to Manual.
Also, you will NOT be able to use the tweetmeme(); function in your WordPress templates, because it writes the same unusable HTML code. Basically, our objective for this plugin or any other TweetMeme plugin is to prevent it from inserting the <iframe> markup directly into your HTML. Here is an example of the useless code that the WordPress plugin wants to crap into your page:
<div class="tweetmeme_button"> <iframe src="http://api.tweetmeme.com/button.js?url=http%3A%2F%2Fwww.seomofo.com%2Fwordpress%2Ftweetmeme-retweet-button.html&source=SEOmofo&style=normal&service=bit.ly" height="61" width="50" frameborder="0" scrolling="no"></iframe> </div>
You DON’T want this <iframe> anywhere in your HTML, for several reasons, but most-importantly because: iframes block your page from loading. We’re going to work around this by using JavaScript to write the <iframe> code into a container element, after the page is done loading. We’ll get to that in a second, but first you need to kill any plugins that put the <iframe> code directly into your pages’ HTML.
Why Does the WordPress Plugin FAIL?
Here is an overview of how the WordPress plugin works, and how it eventually forces your pages to wait for the TweetMeme <iframe> to load.
- WordPress builds an
<iframe>(server-side) and inserts it into the HTML code of a page. - Server sends the page to the client. (e.g., a visitor’s web browser)
- Web browser sees the
<iframe>and requests itssrcfile. Browser waits forsrcfile to load completely before firing the onload event. - Your page can’t finish loading until the Retweet Button finishes loading.

First Steps for TweetMeme WordPress Plugin Users
Good Idea: Go to the TweetMeme settings menu and change the Position option to Manual.
Better Idea: Uninstall or deactivate the TweetMeme Retweet Button plugin. (fewer plugins = faster page speeds)
Why does the TweetMeme button’s custom <script> suck?
The second method for installing the TweetMeme Retweet Button is to insert a <script> element into your HTML code, at the point where you want the button to appear. For details about this method, you can view the TweetMeme Button documentation from TweetMeme.com. Or…just keep reading.
At a bare minimum, you would need to include the <script> element that calls the JavaScript file, button.js, from TweetMeme’s servers. In addition, there are 4 parameters that you could use to customize your Retweet Button. I’ll explain them briefly:
- tweetmeme_url – the URL your retweet will link to on Twitter. By default, the button uses the URL of the page it’s on, so you don’t need to include this parameter unless you’re embedding the retweet button on Page A, but you want your Twitter status update to link to Page B. (For example, this would be handy for adding a retweet button to your RSS feed.)
- tweetmeme_source – the Twitter @username that will appear after the “RT.” By default, this parameter is set to “tweetmeme,” which results in retweets like this: RT @tweetmeme TITLE URL
- tweetmeme_style – choose between normal or compact button design. Default is normal. The compact button looks like this (I added the drop shadow):

- tweetmeme_service – choose one from TweetMeme’s list of URL-shortening services. Default is ow.ly.
The following code is an example of the kind of crap that the script method might use. Theoretically, you would paste this directly into your pages’ HTML code.
<script type="text/javascript"> tweetmeme_url = 'http://yoururl.com'; // only necessary if different from current URL tweetmeme_source = 'SEOmofo'; // Twitter @username that will be retweeted tweetmeme_style = 'compact'; // only add this line if you want to create a smaller button tweetmeme_service = 'bit.ly'; // URL shortening service you want to use </script> <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"> </script>
Are we going to be using the custom <script> parameters? No, not exactly. But you need to be familiar with them for our final method of installing the retweet button. We won’t be using them within <script> tags, but we will be using them to create a custom src URL for our iframe.
The reason why we DO NOT want to use these <script> tags is the same reason we don’t want to use the <iframe> code directly: they block the page from loading. When a web browser is rendering the page, it will see the <script> tag that references the button.js file and immediately send a request for it. To make things worse, the button.js script uses document.write(); statements to insert the <iframe> code into your document…and then we’re back to square one, waiting for the <iframe> to load. In other words, this method for installing the retweet button is actually worse than the WordPress plugin, because instead of building the <iframe> code on the server side, it has to request button.js (client side) and wait for it to build the <iframe> for you.
Why Does the Custom <script> FAIL?
Here is an overview of how the <script> method of installing the button works, and how it eventually forces your page to wait for the <script> to build your <iframe> code and then waits for the TweetMeme <iframe> content to load.
- Server inserts custom
<script>elements into the HTML code of a page. - Server sends the page to the client. (e.g., a visitor’s web browser)
- Web browser sees the
<script>and requests itssrcfile. Browser waits forsrcfile to load. - Src file inserts an
<iframe>into our document. - Web browser sees the
<iframe>and requests itssrcfile. Browser waits forsrcfile to load completely before firing the onload event. - Your page can’t finish loading until the Retweet Button finishes loading.

The Solution
Load the TweetMeme Button AFTER the Page Loads
Despite all the bad things I’ve said about iframes and scripts, we’re actually going to use both in our implementation. The difference is we’re going to host our own JavaScript, and we’re not going to insert the TweetMeme button’s <iframe> into our document until after everything else is finished loading.
STEP 1: Build Your Button’s <iframe> Code
Instead of relying on WordPress or button.js to build our <iframe> code, we’re going to do it ourselves. Don’t worry, it’s much easier than it sounds. To accomplish this, we first need to understand what button.js actually does. Here is the JavaScript code after I’ve formatted it and added comments to it. FYI, I’m not an expert on JavaScript, so my interpretation of this code might be totally wrong. But if you’ve read this far…there’s no turning back now, sucker!
// Get page URL
var _url = window.location.href;
// Remove illegal characters
var _url = _url.replace(/((?:\?|&)?fbc_receiver=.+)?(?:#.*)?$/, "");
// Convert your custom script parameters into local JavaScript variables.
// Make sure they are strings and escape illegal characters.
var url = escape(typeof tweetmeme_url == "string" ? tweetmeme_url : typeof TWEETMEME_URL == "string" ? TWEETMEME_URL : _url).replace(/\+/g, "%2b");
var source = typeof tweetmeme_source == "string" ? escape(tweetmeme_source) : typeof TWEETMEME_SOURCE == "string" ? escape(TWEETMEME_SOURCE) : false;
var style = typeof tweetmeme_style == "string" ? escape(tweetmeme_style) : typeof TWEETMEME_STYLE == "string" ? escape(TWEETMEME_STYLE) : "normal";
var service = typeof tweetmeme_service == "string" ? escape(tweetmeme_service) : typeof TWEETMEME_SERVICE == "string" ? escape(TWEETMEME_SERVICE) : false;
// Apparently, if your URL-shortening service offers an API, you can
// configure it with the tweetmeme_service_api parameter. I couldn't
// find any documentation on this parameter from TweetMeme, so I'm not
// sure about this.
var service_api = typeof tweetmeme_service_api == "string" ? escape(tweetmeme_service_api) : typeof TWEETMEME_SERVICE_API == "string" ? escape(TWEETMEME_SERVICE_API) : false;
// I didn't see any TweetMeme documentation about the tweetmeme_alias
// parameter, so I have no idea what this does.
var alias = typeof tweetmeme_alias == "string" ? escape(tweetmeme_alias) : typeof TWEETMEME_ALIAS == "string" ? escape(TWEETMEME_ALIAS) : false;
// This is our iframe src URL before we've added our custom parameter
// values to it in the form of a query string.
var src = "http://api.tweetmeme.com/button.js";
// This is a poorly-programmed way of setting the height and width of
// our iframe. (BTW...I tried using the rednose style but nothing
// happened. It looked just like the default style.)
switch (style) {
case "compact":
var h = 20;
var w = 90;
break;
case "rednose":
var h = 61;
var w = 50;
break;
default:
var h = 61;
var w = 50;
break;
}
// Add our page URL to the src URL
src += "?url=" + url;
// Add our button style option to the src URL
src += "&style=" + style;
// If we defined a value for the tweetmeme_source parameter,
// then add it to the src URL.
if (source != false) {
src += "&source=" + source;
}
// If we defined a value for the tweetmeme_service parameter,
// then add it to the src URL.
if (service) {
src += "&service=" + service;
}
// If we defined a value for the tweetmeme_service_api parameter,
// then add it to the src URL.
if (service_api) {
src += "&service_api=" + service_api;
}
// If we defined a value for the tweetmeme_alias parameter,
// then add it to the src URL.
if (alias) {
src += "&alias=" + alias;
}
// Insert iframe code into our page
// (where we placed the script tags).
document.write('<iframe src="'+src+'" height="'+h+'" width="'+w+'" frameborder="0" scrolling="no"></iframe>');
// Inexplicably reset this huge fuckin' pile
// of redundant JavaScript variables.
tweetmeme_url = null;
TWEETMEME_URL = null;
tweetmeme_source = null;
TWEETMEME_SOURCE = null;
tweetmeme_service = null;
TWEETMEME_SERVICE = null;
tweetmeme_service_api = null;
TWEETMEME_SERVICE_API = null;
tweetmeme_style = null;
TWEETMEME_STYLE = null;
As you can see, the button.js script really doesn’t do much. All we really have to do is take this <iframe> code and replace the variables with our own values:
<iframe src="src" scrolling="no" frameborder="0" width="w" height="h" ></iframe>
To build your src variable, you can follow this pattern:
- Start with http://api.tweetmeme.com/button.js
- Add ?url= followed by your page URL (for right now, just use URL as a placeholder)
- Add &style= followed by either normal or compact.
- Add &source= followed by your Twitter username.
- Add &service= followed by a URL-shortening service from this list:
- bit.ly
- awe.sm
- cli.gs
- digg.com
- is.gd
- tinyurl.com
- tr.im
- su.pr
- ow.ly
- twurl.nl
- If you have a URL-shortener API, add &service_api= followed by your API key. (Only available for awe.sm, cli.gs, digg.com, and su.pr services. I’m not sure if you’re really supposed to put your API key here or not. Frankly, I just made that up.)
Your completed src variable should end up looking something like this:
http://api.tweetmeme.com/button.js?url=URL&style=normal&source=SEOmofo&service=bit.ly
Now set the w and h attributes.
For a normal style button: width="50" height="61"
For a compact style button: width="90" height="20"
Now that you have your values for the variables src, w, and h, you can plug them back into your <iframe> code, which should now look something like this:
<iframe src="http://api.tweetmeme.com/button.js?url=URL&style=normal&source=SEOmofo&service=bit.ly" scrolling="no" frameborder="0" width="50" height="61" ></iframe>
STEP 2: Create a Container for Your Retweet Button
In Step 1, we created our own <iframe> code. Our goal is to store that code in a JavaScript function that we can call after the onload event is triggered. In order for our JavaScript function to work, our web page needs to have a containing element ready to insert the <iframe> code into. This element should have a unique id attribute assigned to it, so that we can tell our JavaScript function exactly where to put the iframe. Here is an example: <div id="tm_button"></div>
If you’re using WordPress, you have several options for getting your container <div> into your page code. I’ve mentioned a few examples below. If you’re not using WordPress or you already know how to do this, then go to Step 3.
- Add it to a select number of posts, by simply typing the code directly into the HTML view of your Edit Post screen.
- Add it to your WordPress theme’s template files, which would add it to all web pages that use that template (e.g., single posts, pages, archives, etc.)
- Add it as a plain text widget in your sidebars.
- Add it to a WordPress hook, by writing a function in your theme’s functions.php file.
- Add it to a Thesis hook, by writing a function in your custom_functions.php file (only available to those of you using the Thesis WordPress theme).
- Create your own WordPress plugin that adds it to certain types of pages.
For Thesis Theme Users
For those of you who are using Thesis, you can use the following example, which is what I’m currently using. It inserts the <div> into all my posts, but not previews of unpublished posts. If you want to customize it in other ways, check out the full list of WordPress conditional tags.
// Define a function that adds your TweetMeme container <div>
// to all posts except for when you're just previewing it.
if (!function_exists('addTMContainer')) {
function addTMContainer() {
if (is_single() && !is_preview()) {
?>
<div id="tm_box"></div>
<?php }
}
}
// Hook your TweetMeme container to a Thesis hook
add_action('thesis_hook_before_headline', 'addTMContainer');
Here is the CSS I’m using to position the <div>:
/* Make room for my button next to the page title */
div.headline_area{position:relative; margin-right:6em;}
/* Move my button to the top right corner of .headline_area */
#tm_box{position:absolute; right:-6em;}
STEP 3: Define Your <iframe> Code as a JavaScript Function
There are several ways to do this, but I’ll show you what I consider the easiest one. Copy your HTML code and paste it into this tool that converts HTML into JavaScript. Select the option that says Build up a string variable that you can use later and give your variable a name. I’ll call mine iframeCode.
Copy the converted code and paste it into whatever program you use for editing JavaScript/HTML/plain text. Here is what my code looks like now:
var iframeCode=""; iframeCode += "<iframe src=\"http:\/\/api.tweetmeme.com\/button.js?url=URL&style=normal&source=SEOmofo&service=bit.ly\" scrolling=\"no\" frameborder=\"0\" width=\"50\" height=\"61\" ><\/iframe>";
If you remember…we still have a placeholder variable where our page URL is supposed to go. We can’t hard-code an actual URL here, because this JavaScript function has to work for any page that calls it. So instead, we make JavaScript get the requesting-page’s URL for us by replacing our placeholder URL with its JavaScript equivalent: document.URL. We can also use JavaScript’s escape() function to encode the URL just like TweetMeme does in their button.js script. Here is our new code:
var iframeCode=""; iframeCode += "<iframe src=\"http:\/\/api.tweetmeme.com\/button.js?url=" + escape(document.URL) + "&style=normal&source=SEOmofo&service=bit.ly\" scrolling=\"no\" frameborder=\"0\" width=\"50\" height=\"61\" ><\/iframe>";
We have defined the contents of our iframeCode variable, but we still need to put it in a function that writes this content into our TweetMeme container <div>. Here is an example:
function tweetMemeButton() {
// If our TweetMeme container doesn't exist,
// then this function will basically do nothing.
if (document.getElementById("tm_box")) {
// This is the code we wrote a second ago.
var iframeCode = "";
iframeCode += "<iframe src=\"http://api.tweetmeme.com/button.js?url=" + escape(document.URL) + "&style=normal&source=SEOmofo&service=bit.ly\" scrolling=\"no\" frameborder=\"0\" width=\"50\" height=\"61\" >";
// Insert our iframe into our TweetMeme container
document.getElementById("tm_box").innerHTML = iframeCode;
}
}
STEP 4: Use the window.onload Event Handler to Call Your Function
The window object has an event handler called onload that occurs as soon as a page is done loading. What we’re going to do now is program our tweetMemeButton() function so that it gets called when the onload event is triggered. In other words, we’re not even going to begin loading our TweetMeme button <iframe> until after the page is officially done loading. In order for us to accomplish this, we can add window.onload = tweetMemeButton; to our JavaScript code, which is now ready to be pasted into an external .js file.
In the name of page speed and site performance, I’ve combined all of my site’s JavaScript files into one. I link to this file from the <head> section of every page on my site. However you want to go about it is up to you, but one way or another you need to put your JavaScript code somewhere where all the pages that need it can access it.
If you’re wondering something like this: “Can’t I just paste the entire code into the <head> section of every page?”, then by all means, go right ahead…and punch yourself in the face. Then do it the right way, by pasting a reference to your external .js file into the <head> section of every page (that uses the TweetMeme Retweet Button). For faster page rendering, it’s best to paste this code after (below) your CSS file references. For example:
<head> ... <link rel="stylesheet" href="http://www.seomofo.com/wp-content/themes/thesis_16/custom/custom.css" type="text/css" /> ... <script type="text/javascript" src="/external.js"></script> </head>
Here is our final JavaScript code, ready to be pasted into your external .js file:
function tweetMemeButton() {
if (document.getElementById("tm_box")) {
var iframeCode = "";
iframeCode += "<iframe src=\"http://api.tweetmeme.com/button.js?url=" + escape(document.URL) + "&style=normal&source=SEOmofo&service=bit.ly\" scrolling=\"no\" frameborder=\"0\" width=\"50\" height=\"61\" >";
document.getElementById("tm_box").innerHTML = iframeCode;
}
}
window.onload = tweetMemeButton;
STEP 5: Share This Super-Amazing Article
That’s right…people are going to wonder why your blog is so damn fast, and when they do…you send them my way. Oh…and for more page speed tips to speed up WordPress, check out my previous masterpiece: WordPress Comments Slow Down Page Speed.
Peace, I’m outta here.
{ comment Leave a comment }
Darren, you have a great educational approach! Thanks for explaining this so well… Thumbs up & returning to this for reference real soon.
What are you thoughts on using the Topsy retweet plugin and FaceBook share and their effects on load time as well… Maybe another post?
Now you’re just being greedy, Dana. ;)
I second this one :)
A facebook share would make this complete :D
Darren you are too funny, and the animated graphic? Nice touch. I took it off recently because of this issue, so thanks.
Excellent stuff :)
Good stuff but the code is going to get a lot more complicated if you want 10 of them on a home page, each referencing a different permalink.
If you have 10 retweet buttons on your home page, you have more-important issues to worry about.
I currently choose to show full content on my home page, but even if I showed excerpts I would still have buttons on every post, just like Techcrunch or Mashable often have it.
Whilst I haven’t done a statistical test on it, blog posts that have more tweets get clicked through to more, just like something with more comments. Success breeds success.
Thus any solution needs to work with multiple buttons pointing to different permalinks.
Your a fucking BEAST!
great. yet one more damned thing to add to my blog functionality overhaul list that’s come from the mofo. You’re just lucky that your ability to share such knowledge is also backed by an excellent ability to communicate the process involved. Otherwise I’d have to go and bother one of the coders I annoy from time to time with requests for guidance.
I have also noticed how slow my blogs can load when running this, it’s such a damn pain! Thanks for sharing these tips they’re really useful
Holy Crap!
Nice that you put this sentence in your post:
“As soon as you realize my animated .gif isn’t actually going to load anything, we can continue…”
But why don’t you put this at the top of the post? It wasn’t even visible on my 24-inch screen!
Time wasted waiting for tweetmeme button to load: 6.5 minutes!
Great post, fantastic writing style! Thanks, Frank
Hello,
One of best posts seen. Am liking.
Will implement on blog at World’s Greatest SEO
thanks for time
A great tutorial Darren, particularly liked when you explain *why* what you’re doing is better than alternative solutions.
Have you given this feedback to the Tweetmeme plugin designer? They could save everyone some hassle by implementing the performance improvements you’ve come up with.
Dan
Oh jesus, I still haven’t sorted out my multiple canonical tags you pointed out. Help…
Excellent information, because yes the tweetmeme button is awful.
Here’s the problem though most people use/implement plugins so they don’t have to get their “hands dirty” monkeying with the code. While I’m not a programmer I can play with code enough to make stuff happen, and this is just a PIA to work with, multiple files all over the place, it’s just not worth it.
Now if you where to wrap this all in neat little plugin, along with the other planned button tutorials, there’s probably a lot more value that way.
To make an analogy, some people enjoy making home made pasta, but most people will sacrifice a bit of taste, and pick up a box in the supermarket because it’s easier to work with ;-)
That’s actually what I planned on doing from the beginning, but I couldn’t find an elegant universal solution. For example, one issue was where to put the JavaScript code. The universal solution would be to give it its own external file and hook the script tag into the head section, but that would have added another HTTP request to your render time. So it was basically 2 steps forward and one step back.
Plus, there’s a huge leap in expectations once you accept the “plugin developer” role. I’m not ready for that kind of commitment; I’m comfortable just being a blogger/World’s Greatest SEO. :P
Think of the link juice though and credability if it was the business. Saying that, I have found a lot of Yoast’s don’t work properly, the complaining would do your nut in. And I know you’re a perfectionist :)
Hi Darren,
Thanks for writing this article, we really appreciate you putting the time and effort into creating it. With your permission (contact me through email) we would like to add your article to our help pages/FAQ.
However I would like to correct you on a couple of points. Firstly iframes do not block your page from loading. They are correctly one of the slowest DOM element to load, however browsers can download information in parallel as long as the information appears on a separate domain. This means that once the iframe DOM has been rendered, your page will continue to load while the iframe gets populated in the background. Most modern browsers can handle multiple simultaneous connections to different domains (approx 6). Our stats show that on fairly large sites of typically 15 buttons to the page, the connection time takes ~120ms for the first 6, then the next 6 takes ~190ms etc (tested in Firefox 3.6 on mashable.com).
You JavaScript solution would cut out the ~0.5 second load time of 15 buttons by ensuring the DOM and content is completely loaded. However your solution doesn’t allow multiple buttons to be replaced in this way. Therefore i propose this javascript:
function tweetMemeButton() {
var div = document.getElementsByTagName(‘div’);
for (i in div) {
if (div[i].className == ‘tweetmemebutton’) {
// grab the url we want to use from the title
var url = div[i].title;
var iframe = document.createElement(‘iframe’);
// removed to keep short
iframe.src = ‘…?url=’ + escape(url) + ‘…’;
iframe.height = 61;
iframe.width = 50;
iframe.scrolling = ‘no’;
iframe.frameborder = ‘no’;
div[i].appendChild(iframe);
}
}
However the benefits of this will only be apparent when the script is included at the bottom of the page, after the DOM has been loaded.
The reason we have yet to implement this is because of the difficulties in the degradation of the button. If the user doesn’t have JS installed this would result in no buttons loading. Another reasons is the configuration options that we allowed and the complications in setting them up for this script. We are currently working on a much improved and more powerful version of the script above for our larger partners which we are happy to share once it has been fully tested.
Daniel
Awesome response, Daniel. Thank you for taking the time to write all that out. =)
Great work, but… I do not understand this step
“Here is our final JavaScript code, ready to be pasted into your external .js file”
:(
Hi Jorge,
I’ll try to explain it better…
1.) The step assumes that you have at least one external .js file that you can add the final JavaScript to. Most WordPress blogs have one. If you don’t have one, you can create your own.
2.) If you aren’t sure whether or not you have an external JavaScript file, you can view your page’s HTML source code and look for script tags in the
<head>section. Mine looks like this:<script type="text/javascript" src="/nobots/mofo.js"></script>3.) Once you have pasted your final JavaScript code into your external file, make sure that the script tags (like the example above) appear in the
<head>section of all the pages that require it (i.e. all the pages that you want the TweetMeme button to appear on).A great post that is well worthy of a retweet.
Karl
Thanks, great info & nice job outlining everything!
This is really useful.
Can you write something for the facebook share button, as that’s become very popular too.
thanks
Tried doing all the steps. The button didn’t show.
Hey its me again. Sorry about the last comment. I spent some hours going through the steps and knowing that it didn’t work gave me a bad mood for nearly 2 days. :\
I tried to change the .js file several times because you seemed to have skipped a step in one of your examples. Like the part in the .js file. All of a sudden the code isn’t closed with a or (and I don’t know why there are extra slashes sometimes). And the part where there’s the tn_button, and all of a sudden there’s the tn_box. I hope you can change the tutorial a bit, and separate the tutorials for wordpress users and plain custom css users.
If it helps, this is what my .js script file looks like. I’ve tried changing the script here and there but still don’t see the button. If possible, I’d like you to reply and tell me what I did wrong in this file.
http://archigeng.webs.com/scripts/externaltweetmeme.js
Notice that I replaced URL with because that’s the tag that changes the URL depending on what post the button is located at.
Anyways, even if it doesn’t work for me, the important thing is that you’ve helped a huge lot of people as seen in the previous comments. Thanks so much for trying to help. :)
“Universal solutions” thinking gave us McDonald’s and an over-burdened pubic school system.
If I have to learn something and work a little harder to make my blog load faster for visitors, I’ll roll up my sleeves and get ‘er done.
Thank you Darren for this tutorial!
Thanks for the info, but in Internet Explorer the above code results in a white background.
I’ve used your code to write http://www.marcorama.nl/p/tweetmeme-button-transparent-in.html.
HTH
Marco
Thanks, between your and Dennis’ code, I was able to speed up an article index page quite a bit. Think the ultimate solution for me would be to use the RSS/Email button, which are very snappy, but apparently there is no “compact” style option for those buttons (or at least I can’t get an answer from tweetmeme) which ultimately wound me up here. This will do for now, going to see if I can’t tap into the API to get a better response time (Displaying 10-15 urls at a time). Here is the code I ended up using with a couple little changes to make it work. Called from external script just before closing body tag. Oh and my button is in an unordered list, so change ‘li’ to ‘div’ or whatever container your button is in in line #2.
function tweetMemeButton() {
var div = document.getElementsByTagName(‘li’);
for (i in div) {
if (div[i].className == ‘tweetmeme’) {
// grab the url we want to use from the title
var url = div[i].title;
var iframe = document.createElement(‘iframe’);
// removed to keep short
iframe.src = ‘…/button.js?url=’ + url + ‘&style=compact&source=&service=bit.ly’;
iframe.height = 20;
iframe.width = 90;
iframe.scrolling = ‘no’;
iframe.setAttribute(‘frameborder’, 0);
div[i].appendChild(iframe);
}
}
}
window.onload = tweetMemeButton;
> iframe.setAttribute(‘frameborder’, 0);
Probably want to do iframe.frameBorder = “0″;
Older versions of IE need that, instead of setAttribute, for frameBorder.
Hi,
I am building a site using Drupal and tried installing the tweetmeme plugin, which I found was limiting because I could not choose where to position the buttom. This article is very helpful; however, the tweetmeme button is only appearing on one story at a time ( and I would like for it to appear on every story that I post). I added the div to the node-story.tpl.php file, however, it is still only appearing once. Does anyone know how I can change the function in order to make the button appear on every post? Thanks!
thank you very much, it really helps.. ;)
wow this is just amazing n damn you are to good a tutor ,thnx a lot for such a nice n easy made post.
thanks very much for info but can you give php code for it to add to wordpress blog
Thanks man this really helped me out. I used it to fix my facebook like button which also uses an iframe. That thing was really starting to slow down my sites load times.
I think this is all fine and dandy, frankly another company needs to step up to the plate to offer a higher performing button. I’ve been testing various buttons.
When I’m using only a single button per page like when I have a single blog posting listed, the Google Buzz button that uses Google’s actual api and servers, connects in .6s where tweetme is 1.2s. When I try to load say ten buttons per page like found on my blog homepage, the transaction times sky rocket even higher for tweetme to 2.93s PER button. They are loading asynchronously, but each button finishes about 100ms longer. The kicker here is the buzz load time for ten buttons only went up to .9s. The reason it didn’t change much because the api/plugin only has a single api call for every button on the page.
Twitter doesn’t support this natively and tweetme’s api is terribly inefficient. Don’t even get me start on the facebook Like button. When there’s 10 Like buttons, that adds 20+ seconds to the complete page load time. They get away with it because it loads in the background, but give me a break. The buzz button is the only button I’m keeping on my homepage with where there are ten buttons. On the individual articles with single buttons, the performance hit is livable.
Great article! It’s the 1st I’ve found to explain the details and take into consideration the user experience rather than giving the easiest way to do it.
However I notice your method only works for is_single() & is_preview(). My client wants the button to appear on index.php and all archive templates too. Any ideas?
I really don´t understand how to do it… :-(
Regards
Linus
Right on! Definitely noticed the slowness when I was working on a site. Kept tuning the database queries until I realized it was the @#$@#$ TweetMeme and Facebook buttons … well, at least the database query is lightning fast now =)
Really amazing article and solution – exactly what I was looking for to play a little bit with the TM-button, because it doesn’t validates. :(
Thanks for sharing your solution! :-)
Hey Darren,
I have a question for you. Yes, I’m addicted to social media widgets. But I want to at least make them faster like you suggested.
I was able to use your idea to use jQuery to inject iFrame media widgets such as the facebook like button quite easily.
$(‘.mydivclass’).html(”)
(Hopefully, that’s an efficient method.)
But here’s my question. How do you suggest going about dealing with these two widgets for “Recent Tweets” and “Recent Reddit” posts? I’ve attached the code to pastebin. — http://pastebin.com/y6AJAD4E
Thanks!
P.S. Just found this site, and I love the humor!
Thanks for this. I managed to speed up page loading by applying this to both Tweetme and Facebook like buttons. The onload Javascript can be made better by appending the function to any other onload functions that may exist:
if (window.addEventListener){
window.addEventListener(‘load’, tweetMemeButton, false);
} else if (window.attachEvent){
window.attachEvent(‘onload’, tweetMemeButton);
}
/me adds tweetmeme.com to his adblock.
problem solved.
Hey nice one…. I am also facing the same tweet problem. Need to try this today itself. Thanks for posting.
Good article Darren. Btw, I shared this article and made you richer! I Hope you feed your 9 children well. Peace.
Darren,
I am shite at PHP and JS and have messed around with so long that my teeth itch. I have been trying to use, abuse, adapt and adopt this to the new Buffer button, which does something similar, only it buffers the tweet…
Buffer
But like I said I am shite at this and can’t get it to work.
Will it work or am I wasting my time?
P.S. Did I mention I am shite at this?
It should work. Here is an example of the iframe code you would use in Step 3 if you wanted to use Buffer instead of TweetMeme:
<iframe src="http://widgets.bufferapp.com/button/?url=URL&count=vertical&via=SEOmofo&source=button" scrolling="no" frameborder="0" width="55" height="62"></iframe>Results in this:
Looks like you just got mofo’d, mofo…
Now let me guess. Your next how-to will be on spam posting protection.
Am I right. Or am I left?
You’re right!
How to Protect Your Blog from Spam Comments
1. Enable Akismet.
2. Hope it works.
3. If it’s not working, ignore the problem and check back later.
4. Repeat steps 2 and 3 until it works.