mootools_MooTools TwitterGitter和Cookies

mootools

TwitterGitter

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。

翻译自: https://davidwalsh.name/mootools-twitter-cookies

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值