开发者

Is there an out of the box Javascript "Tweet this" link solution with URL shortening, which does not eagerly load files from other domains?

开发者 https://www.devze.com 2022-12-17 14:27 出处:网络
Requests to third party servers keep slowing my site down, so I am trying to have as few as possible.

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 smal开发者_如何学JAVAl 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.


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.


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


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号