2011-11-26 55 views
1

我试图通过简单地使用@anywhere API Twitter来在我的网站上放置一个推文框。虽然这工作得很好,是简单的设置,它具有下列问题吧:Twitter @Anywhere API的替代品?

是否有任何其他替代方案使用@anywhere

编辑:这是我的代码..

<div id="twitter_widget"> 
     <script src="http://platform.twitter.com/anywhere.js?id=**MYAPPID**&v=1"></script> 
     <script type="text/javascript"> 
     twttr.anywhere(function (T) { 
      T("#twitter_widget").tweetBox({ 
      label: "<span style='display:block !important;margin-bottom:5px !important;font-family:Helvetica Neue !important; color: #CCC !important; font-size: 18px !important; font-weight: 500 !important;'>Tweet</span>", 
      height: 100, 
      width: 300, 
      defaultContent: "" 
      }); 
     }); 
     </script> 
     <button class="check-twitter" onclick="window.open('http://www.twitter.com','_blank');">Go to Twitter</button> 
    </div> 
+0

什么是您的主机环境? – rds

+0

从Hostgator托管的VPS。 – Charlie

回答

1

我不知道替代@anywhere的。但我不相信3s/14的要求会影响你。

从Twitter的文档 -

“为@Anywhere功能全部依赖被异步加载, 点播,以便不影响主机页面的性能”

总之,这意味着你的页面是几乎从Twitter的库中分离出来。即使Twitter的小部件花费很长时间加载,用户也应该能够使用您的页面。它不能解决“加载14个请求”的问题,但它确保Twitter的性能问题不会成为你的问题。

请注意,我说差不多是以上。加载外部脚本作为你的一部分可能会减慢你的整个网站。如果Twitter的服务器面临问题,则可能会导致Front End Single Point of Failure

更新:Per Twitter, loading anywhere.js asynchronously isn't supported。我在下面提到的解决方案可能会或可能不适合您,谨慎行事。

因此,我能想到的最佳解决方案是异步加载anywhere.js本身。只是你的收盘 </head>


//Assumes jQuery was loaded 

jQuery.getScript("http://platform.twitter.com/anywhere.js?id=&v=1", function(data, textStatus) { 
twttr.anywhere(function (T) { 
      T("#twitter_widget").tweetBox({ 
      label: "Tweet", 
      height: 100, 
      width: 300, 
      defaultContent: "" 
      }); 
     }); 
}); 


把这段代码 - 如果你使用jQuery,代码会喜欢这个。它将异步加载anywhere.js,并且仅在js加载后调用twitter的函数。

+1

多么可怜。是的,@anywhere有很多问题 - 缓慢或有时下降。 – Till

1

如果你想使用@anywhere,你不能做的不多。我一开始就注意到了随机事件(比如停机时间和什么)。但通常platform.twitter.com应该足够快,因为它是由Akamai提供的。

你是如何确定它是三秒钟的,究竟需要三秒钟?整个页面,或者只是加载外部JS等?

您唯一的选择是使用另一个不依赖于第三方代码的选项。这是唯一的快速选项。第三方网站总是会很慢,除非有SLA来保证可用性和性能。

+0

你指的是第三方网站? – Charlie

+0

任何!当您包含来自不在您控制范围内的域的代码时,问题始终存在。我们通常会对外部资源进行版本管理(如果可能),并将它们粘贴到“供应商”目录中,并将它们结合起来进行生产。这在@anywhere中是不可能的。 – Till

+0

只是出于好奇,结合了什么意思呢? – Charlie

1

另一种方法是让您的网站成为Twitter客户端。这需要您支持oAuth & Twitter API。

+2

你有这方面的指导吗? – Charlie