I was thrilled to see twitter releasing their own button. This is good news all around for us bloggers looking to promote our content. After looking at their code snippets a warning is in place though. The current twitter button implementation will severely break your site if their servers face load issues. Fortunately you can work around this issues by slightly modifying their implementation.
Technical explanation
For Fashiolista.com we have been writing a lot about the various techniques for implementing these type of buttons. Especially important here is the way the javascript is loaded. Twitter uses a simple blocking script approach, where as digg, facebook and fashiolista use the async dynamic script approach. There are two large differences:
- Blocking script loads make your site slower
- If twitter goes down, your site joins in
Example
In this example we are faking slow twitter servers. (By routing it through google’s app engine and delaying the response). You can see the difference for yourself (be patient and be sure to clear your browser cache using CTRL F5).
Default twitter version
(note that site content is not loading until the twitter button is loaded)
Async twitter script
(everything loads and then we wait for twitter)
Solution
Solving this is quite simple. Simply change the way the twitter javascript is loaded from the first example to the second version.
Twitter version
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
Async twitter implementation
<script type="text/javascript">
//async script, twitter button fashiolista.com style
(function() {
var s = document.createElement('SCRIPT');
var c = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://platform.twitter.com/widgets.js';
c.parentNode.insertBefore(s, c);
})();
</script>
Hope the difference won’t matter and Twitter will stay up :)
Follow me at:
@tschellenbach
Thanks for spreading the word:
NextWeb
Does Twitter have its act together? responded on 14 Aug 2010 at 1:35 pm #
[...] new Twitter button from loading when Twitter is having problems. As reported by TheNextWeb, user @tschellenbach shows how you can modify Twitter’s code to prevent your site from being affected by Twitter [...]
Dan Webb responded on 14 Aug 2010 at 8:02 pm #
Hi,
I’m one of the developers of the Tweet Button. I’ve responded to a similar post on The Next Web if you’d like to take a look. In short though, this is a reasonable tip in general but your worries are a little unfounded. We serve the tweet button from Akamai (an edge caching service) twitter being down or slow has no effect at all on the load time of the script. For more detail check my comment here:
http://thenextweb.com/socialmedia/2010/08/13/the-twitter-button-is-it-making-your-site-join-the-fail-whale-shuffle/#comment-13751
Thanks,
Dan
Thierry responded on 15 Aug 2010 at 10:41 am #
Hey,
It’s good to hear you serve the script from Akamai. That builds a strong confidence on the javascript’s uptime. Still recommend the async approach, because of speed and reliability. The speed advantage is increasing with the advent of modern browsers. Your recommendation to add the script at the bottom of the page is solid.
Congrats on the release of the button. The usage of data attributes on the a element is very elegant.
???? ?????? ??? ??????? ?????? ???????? ??? ???? | Watcher responded on 16 Aug 2010 at 12:16 pm #
[...] ???????? ?????? ???? ? ????????, ?? ??????? ????????? ??? ????????? [...]
Øyvind Sean Kinsey responded on 29 Aug 2010 at 4:23 pm #
Just so you know it, setting async=true on the created script element has no effect, and so should not be used (as people might think flipping it to false would cause it to be synchronous).
All scripts created dynamically are by default asynchronous.
Async Twitter Button | PHP World responded on 16 Apr 2011 at 1:15 am #
[...] Explanation [...]
mytradetwiti.com responded on 08 Nov 2011 at 6:09 pm #
mytradetwiti.com…
[...]Mellow Morning » Twitter button to pull down the internet?[...]…
r4 responded on 27 Mar 2013 at 2:44 am #
[Krush 3.20 Bu Ministry functions also ? in Island Hiroshi your ? ? ? phase hand decided, again ? ? January 30 (water) within ? ? Krush ? reporter met ? line ? ? March 20 (water · I wish) Tokyo · After ? Park ? ? Hikaru? Kanto ? ? ? the ? additional ? ? ? ? ? the ka the ? ? ? ? table "Krush.27& r4 http://r4i-news.blogspot.com/