I’m currently building a SPA and hosting it on Netlify. So far all is going great. Now I’m thinking about how can I provide basic SEO / OG needs, mainly just generate the right
<meta> tags on the server. I don’t really need a full SSR of the entire app, just SSR the meta tags and I can completely hardcode it, after all, this meta tag logic does not even need to be duplicated within the client app, the meta tags don’t need to change on client-side transitions (AFAIK).
I know I could be using Netlify Prerendering to do a full SSR prerender of the app, meta tags included. But that approach has two downsides:
- The HTML can get stale. I need to bust cache ASAP after the user edits their data via API.
- I’d have to put the meta rendering logic in my client-side code and it would increase the bundle size. Wiring that logic on the client is more complex than a simple string concat on the server.
So that’s why I’m looking at Netlify Functions as a promising solution to my problem! After briefly looking at them, it seems to me like they’re primarily focused on JSON serving than HTML serving but maybe it could still be a good match?
Basically, I’d need a wildcard lambda that would check the URL and either just serve the HTML skeleton, or do a node-fetch, open the index.html, split it and inject as some tags there and then serve. Is that doable? Would such a lambda then have to even take care of serving assets? Unfortunately due to my routing needs, I’d need to run it at
/* to render pages like
Thanks a ton! I’ve been a big fan of Netlify since its beginnings.