1

I am currently working on a custom URL shortener and am trying to figure out how to "inject" my own social preview metadata dynamically for each page. (eg. for Twitter Cards) I had originally planned on doing this in much the same way as I am with the actual redirect, fetching the data using the JavaScript fetch API. After reading a little more though it does not appear that this approach will work since it doesn't look like the twitter (and other social media web crawlers) run JS when looking for the metadata.

Is this correct?

If so, is there a way I can load the metadata from a dynamic source instead of just having to create a new html file for every redirect?

It looks like I can probably do something, at least for the image based on a test of this link (using https://source.unsplash.com/random for the image) through the twitter card validator. But what would be the best approach to doing something similar? Everything I can think of would use JS.

kevinuulong
  • 530
  • 1
  • 4
  • 17

1 Answers1

0

I have similar pages in production.

You'll need to use a server-side language (like PHP, or node.js) to set the meta tags for your twitter cards, and use javascript to redirect the page.

Joundill
  • 6,828
  • 12
  • 36
  • 50