Tweet Embeds WordPress Plugin

When you embed Tweets on your website, Twitter asks you to include their JavaScript code that adds images, number of likes, and loads their styles.

But looking at the size of all the script files (yes, the one script tag loads multiple JavaScript files), does quite a bit more than that, including tracking your website’s users.

And it has pretty negative impact on your site’s performance as measured by Google PageSpeed.

Let me illustrate this with my own website. The home page is pretty bare, it has a bit of text, a few small images in the footer, and one embedded Tweet.

Here’s the PageSpeed score for desktop and mobile side by side.

My site is already pretty optimized for performance, so it’s pretty easy to see what stands out.

As you can see, the one Tweet comes with one script tag that loads at least two additional JavaScript files, each of which is at least seven times larger than jQuery, a widely used library with a ton of functionality. That really makes you wonder what Twitter’s scripts are actually doing.

A quick look at their privacy page gives you an idea. (Emphasis mine.)

When you view Twitter content or Twitter products integrated into other websites using Twitter for Websites, Twitter may receive information including the web page you visited, your IP address, browser type, operating system, and cookie information.

One alternative is to use Twitter’s API to get the details of embedded Tweets. And my new WordPress plugin does exactly that, you only need to provide your own API keys. (The plugin will still work without them, but some data, like profile pictures, number of likes and retweets, will be missing and media — images, GIFs, videos — will not render.)

Here’s my site’s PageSpeed score after enabling the plugin.

Much better!

And here’s a few examples of the plugin in use, showing a variety of Tweets. (And you can find even more on Botwiki.)

For website previews, it uses my own SiteSummary API.

One limitation of Twitter’s API is that it doesn’t provide URLs of attached videos, so for now videos only show a thumbnail with a link to Twitter and I expect to add inline video playing in the future.

And just to drive the point home even more, here’s the PageSpeed score for this very page, without the plugin and with the plugin enabled.

You can download this plugin from the WordPress plugin directory, and the source code is on GitHub. Feel free to reach out with bug reports and feature requests!

And if you like this project, be sure to also check out my Simple Sharing Buttons Generator.

More projects

Creative Bots

A project template for making creative online bots.

Browse all

Close

Adblocker not detected

Consider installing a browser extension that blocks ads and other malicious scripts in your browser to protect your privacy and security.