Twitter og:image card not displaying for first time

1.2k Views Asked by At

Integrate twitter og cards on my site. While sharing on twitter everything works fine except image which is not loading for first time. After that it works fine but for first time image is displaying .

Is that an issue or its work like that? If issue then how can I fix that?

1

There are 1 best solutions below

1
On

I've had this problem too. It seems to me that this is what's happening:

When Twitter or the validator inspects your URL, it calls a backend function to create the thumbnail image and store it in Twitter's CDN. But the JS code you are running in your browser times out on that call after 2 or 3 seconds.

So, if for whatever reason (image size, processing, transfer time, protocol negotiation, etc), it takes the Twitter function more than that to retrieve the image from your site, produce a thumbnail and store it, the JS code in the browser is not listening anymore.

The function keeps running, and eventually finishes. And that's why the subsequent attempts all work, because the thumbnail is already in Twitter's CDN.

So, the solution is to make the site deliver those images as fast as possible. Big files naturally will take longer to transfer and process so you should look into that as well.