xobqpq
Last Updated: February 25, 2016
·
403
· scott2b

A couple of notes about embedding Tweets

Twitter's documentation on embedding tweets on your page is here: https://dev.twitter.com/docs/embedded-tweets.

A couple of key points are missing here. Firstly, under best practices, the docs state "Cache the oEmbed response on your server," but a better practice in my mind is to eliminate the call altogether. It's not clear to me why Twitter is advocating this wasteful practice anyway. The docs go through the trouble of telling you how to manually construct a tweet blockquote, but then go on to push the oEmbed calls for getting the HTML from their servers. Better yet, just construct the blockquote HTML yourself and eliminate the need to get it from Twitter or to cache the response on your server.

Secondly, if you are dynamically pushing tweets into your page and you have a single reference to Twitter's widgets.js as advised, you may find that your tweets don't get rendered. The solution is to make a single call to twttr.widgets.load() after constructing a group of tweets on the page. This call will trigger the widgets script to render the blockquotes into tweets.