views:

200

answers:

2

Requests to third party servers keep slowing my site down, so I am trying to have as few as possible.

In my book, the ideal "tweet this" solution should

  • be a small javascript snippet to be hosted on my own site
  • not have any activity while loading the page (at least as few as possible, but no additional HTTP requests)
  • just when clicked, retrieve short url and tweet it

Is there anything like this? All solutions I have found do load stuff from other servers while my page is loading.

I would not mind to do some of the scripting around this myself, but of course I do not want to re-invent the wheel, if there is a good solution around.

Thanks a lot in advance


EDIT: In case anyone is interested in what I finally ended up with.

I decided to implement the API call in my backend, triggered by an AJAX request when the user clicks a button. From the client perspective, this solution needs least resources and is as lazy as it can be. Plus: addressing the bit.ly API directly is really trivial.

However: retweet.js (posted below) is still the best out-of-the-box client-side solution I have seen so far.

Thanks for your input :)

+2  A: 

Not 100% certain this is what you're after, but have you had a look at this? Easy Retweet Button by John Resig http://ejohn.org/blog/retweet/

It uses bit.ly to shorten urls and forwards the user to their Twitter login page.

Oh, and it uses jQuery which can be hosted on your site. :-D

Jonny Haynes
In fact, it doesn't depend on jQuery at all, so it's just a standalone script.
vrutberg
Thanks a lot, on the first glance it seems to be exactly what I am after. I'll try it and keep you updated.
PeterP
@vrutberg - oh - I just presumed because it was John Resig
Jonny Haynes
Actually it does not meet all of my requirements since it fires external HTTP requests while the page is loading, but nevertheless it is the best solution I have seen so far, as it does not make use of document.write, at least :) Thank you Jonny.
PeterP
that's no problem :-)
Jonny Haynes
A: 

You could go with a really lo-fi solution and simply link to the Twitter page from your home page. Add a link like this:

<a href="http://twitter.com/home?status=[mystatus]" target="_blank">Tweet this!</a>

... where [mystatus] would be some string representing the tweet you want the user to send.

This link, when clicked on, will open a new window/tab and, if the user is logged into Twitter, will populate the status message input with the [mystatus] string. If the user is not logged in, they'll get redirected to the Twitter login screen and after a successful login their status input will be populated with the [mystatus] string.

You would need some kind of solution to customize the [mystatus] string to contain what you want it to contain. Some options:

  • You could do this with a server-side language: construct and populate the href attribute of the anchor tag before the HTML is composed and sent to the client.
  • You could also do this with JavaScript after the page loads: attach some function on page load that will change the href attribute of the anchor tag to contain the status message you desire.
fil maj
Thanks for your input on this... thought about this, too, but it is not really an option for me, since it does not feature URL shortening, and some of my URLs are really long
PeterP