Metatags in React site

Hello,

  • I’d like to create some metatags in a static page the content of which would be the result of a query to an API (so that crawlers can see these tags which are currently created using JavaScript with ReactJS). Perhaps using templates coupled with the proxy directive?

In other words, is it possible to include in a page the content of a response from an external HTTP service?

Thanks,
a

Hi @aodh, welcome to the Caddy community!

Caddy can either proxy (get the entire page content from somewhere else) or it can serve a static file (perhaps using templates to fill in some information), but I don’t believe there’s a way to have Caddy itself fetch dynamic content from elsewhere to insert into a static page.

You might need to look into using a scripting language like PHP, or embed some JavaScript in your page that has the client’s browser itself fetch and render the required content.

This is easily doable in Caddy 2, FWIW. Would you like to give it a try? You can use templates for this, since Caddy 2 templates can make HTTP sub-requests.

1 Like

@matt Thanks! How do I get started? It looks like Caddy 2 is still in development?

@Whitestrake The problem with the JavaScript approach is that it will be too late in the loading lifecycle so to speak for any crawlers to read their contents.

Sure is, but I’m already using it in production: https://matt.life, https://finerpixels.com, and https://doesmysiteneedhttps.com as examples.

Here’s how to get started: https://github.com/caddyserver/caddy/tree/v2#install

Are you sure? https://developers.google.com/search/docs/guides/javascript-seo-basics

@matt Yes, I am sure. The crawlers I’m referring to are Twitter & Facebook’s…