A tinted collage of multiple tweets.

Alternative Tweet Embeds

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. (You can find even more on Botwiki.)

You also get website previews.

And just to drive the point home even more, here’s the PageSpeed score comparison for this very page.

You can use this project as a WordPress plugin (the source code is on GitHub) or host it yourself on Glitch (view source here).

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.

A tinted screenshot of the Fediverse Export Analyzer interface, showing a visualization of Mastodon user account with profile image and description in the left column, and various details, including account creation date, embedded first post, and posting frequency, and a scatter plot of all posts.

Alt Text Hall of Fame

Making the web a friendlier and more inclusive place, one captioned image at a time.

#accessibility #alt-text #image-descriptions #internet #web #web-accessibility

A tinted screenshot of three embedded Mastodon posts.

💻 Browse all