mootools
One of my MooTools plugins I use most is TwitterGitter. TwitterGitter is a small MooTools plugin I've created to fetch any number of tweets from an Twitter user's account. Since clients don't tweet very often, there's no advantage to pinging Twitter for a tweet every page load. To save Twitter a bunch of repetitive requests, I use cookies to save the latest tweet.
我最常用的MooTools插件之一是TwitterGitter。 TwitterGitter是我创建的一个小型MooTools插件,用于从Twitter用户的帐户中获取任意数量的推文。 由于客户不经常发推文,因此对Twitter进行ping操作以获取每次页面加载的推文没有好处。 为了保存Twitter一堆重复的请求,我使用cookie来保存最新的tweet。
MooTools JavaScript (The MooTools JavaScript)
var tweet = '';
if(!Cookie.read('latestTweet')) {
var myTwitterGitter = new TwitterGitter(init.twitterHandle,{
count: 1,
onComplete: function(tweets,user) {
tweets.each(function(tweet,i) {
if(tweet.text) {
Cookie.write('latestTweet',tweet.text, { duration: 1 });
tweet = tweet.text;
}
});
}
}).retrieve();
}
else {
tweet = Cookie.read('latestTweet');
}
Pretty simple: if the cookie is there and fresh, use the cookie's value as the tweet; if not, go get the tweet from Twitter. Of course the most optimal method of saving tweets is caching them server-side but if you use TwitterGitter, I recommend using cookies to avoid unnecessary pings to Twitter.
非常简单:如果有cookie且新鲜,则使用cookie的值作为推文; 如果没有,请从Twitter获得推文。 当然,保存推文的最佳方法是在服务器端缓存它们,但是如果您使用TwitterGitter,我建议使用cookie以避免不必要地ping到Twitter。
mootools