Skip to content

Embed tweets on your site without compromising your users' privacy and your site's performance.

License

Notifications You must be signed in to change notification settings

stefanbohacek/alternative-twitter-embeds

Repository files navigation

Alternative Tweet Embeds

Alternative Tweet Embeds

Embed tweets without compromising your users' privacy and your site's performance.

Learn more on stefanbohacek.com. Also available as a WordPress plugin.

How to use

Remix this project and update .env file with your own Twitter API keys. (See instructions inside that file.)

You can then open your project to see how to add necessary style and script tags to your page.

View project page Add scripts and styles

Be sure to remove any script tags from the embed code that Twitter gives you.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link href="https://alternative-twitter-embeds.glitch.me/css/styles-bs.css" rel="stylesheet" type="text/css">
</head>
<body>
    <TWEET CODE>
    <script src="https://alternative-twitter-embeds.glitch.me/js/tweets.js"></script>
</body>
</html>

If you're using Bootstrap v4 on your site, you can load an alternative slimmed down stylesheet.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link href="https://alternative-twitter-embeds.glitch.me/css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
    <TWEET CODE>
    <script src="https://alternative-twitter-embeds.glitch.me/js/tweets.js"></script>
</body>
</html>

Performance improvements

See a comparison of the PageSpeed performance test results between this project's page and the test page.

A comparision of PageSpeed performance test results between two pages, one using this project and one using Twitter's scripts

Questions and tips

Need help or want to share feedback or suggestions? Feel free to reach out via email or on Twitter!

I want to run some code after all tweets are processed

Use the tembeds_tweets_processed event.

document.addEventListener('tembeds_tweets_processed', () => {
  const tweets = document.querySelectorAll('.twitter-tweet');
  console.log('tweets are ready', tweets);
});

Here's an example using jQuery.

$(document).on('tembeds_tweets_processed', () => {
  const $tweets = $('.twitter-tweet');
  console.log('tweets are ready', $tweets);
});

How do I prevent others from using my app?

Use the ALLOWED_URLS variable inside your .env file.

ALLOWED_URLS='alternative-twitter-embeds.glitch.me'

You can list multiple domains, separated by a comma.

About

Embed tweets on your site without compromising your users' privacy and your site's performance.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published