I'm attempting to put a tweet box on my website by simply using the @anywhere API by Twitter. While this works fine and is simple to set up, it has the following problems with it:
- Take over 3 seconds to load ( https://stackoverflow.com/questions/19907/what-do-most-users-consider-acceptable-load-times-on-a-website )
- Makes 14 requests
- Calls jQuery twice
Are there any other alternatives to using @anywhere
?
Edit: Here's my code..
<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>
I am not aware of alternatives to @anywhere. But I don't believe the 3s / 14 requests affect you.
From Twitter's documentation -
In short, this means your page is almost decoupled from Twitter's library. The user should be able to use your page even if Twitter's widgets take a long time to load. It doesn't solve the "loading 14 requests" problem, but it ensures Twitter's performance problems don't become yours.
Notice that I said almost above. Loading an external script as part of you can slow down your entire site. If Twitter's servers are facing a problem, it can lead to a Front End Single Point of Failure.
UPDATE : Per Twitter, loading anywhere.js asynchronously isn't supported. The solution I mention below may or may not work for you, proceed with caution.
So, the best solution I can come up with is loading anywhere.js itself asynchronously. If you are using jQuery, the code would like this -Put this code just before your closing
</head>
. It will load anywhere.js asynchronously, and call twitter's function only after the js has loaded.