How to inject Open Graph/Meta tags for Social Media before the sendFile function? #7280
Replies: 2 comments 2 replies
-
|
Hi, I'd like to work on this issue. I think I can implement a solution by caching the HTML template and injecting dynamic Open Graph meta tags before sending the response. Please let me know if this approach aligns with the expected direction. |
Beta Was this translation helpful? Give feedback.
-
|
The easiest thing that I can think of would be using a template (derived from your SPA's If you really want to use streams, then you can try using I'm not sure if serving open graph properties only to bots/crawlers makes sense, because while most will likely have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In short: can we transform the file to be sent while piping? This for social media 🤷♂️
Longer version:
I wonder what's the recommendation how to inject HTML meta headers for social media scrapers, before sending the
index.html, using sendFile.Because, my SPA application, used by thousands of users a week, I load video X with a GET request by ID. That video comes with a title and description. This using Express.js in routes. Once loaded over DB, I want to set the ogDescription meta tag with its description, for example. But how?
Facebook comes with this tool to check:
developers.facebook.com/tools/debug
It requires a static HTML file. Before, I was using this npm package react-metatags-hook which was a bad idea. Because that Facebook scraper tool requires a plain HTML file.
I know, SSR or SSG would be the ideal solution. But I don't have the time to migrate my app to SSR/SSG right now. That would be a big step and requires a lot more testing and is too risky.
The current code to serve the static index.html for the SPA is:
This index.html does not come with
og:descriptionfor example because it's content/video based. I want to add it dynamically for bots/scrapers only.Some ideas
sendFile, open the original file, alter it, inject more HTML meta headers and send that (feels too complicated and poor performance)sendFilefunction: a transform stream. Customisable. Inject HTML headers etc.Perhaps this has been raised, discussed before?
Ideas welcome. Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions