[Solved] SSR - server-render for head using blaze

Hey All,

I’ve been going down a rabbit hole trying to figure out how I can get dynamic tags in the head.

My setup is blaze using flowrouter with the meta package add on.

I’ll basically do anything that works with my setup to get the go meta tags to pre-render so that I can have dynamic social sharing tags based on the page contents. That excludes paying for a service to pre-render.

Adding head content with SSR can be done with the server-render package:

import { onPageLoad } from "meteor/server-render";

onPageLoad(sink => {
  // parse sink.request.url to get correct content, then:
  sink.appendToHead(`
<meta property="og:title" content="SSR - server-render for head using blaze">
<meta property="og:description" content="Hey All,  I’ve been going down a rabbit hole trying to figure out how I can get dynamic tags in the head.  My setup is blaze using flowrouter with the meta package add on.  I’ll basically do anything that works with my setup to get the go meta tags to pre-render so that I can have dynamic social sharing tags based on the page contents. That excludes paying for a service to pre-render.">
<meta property="og:image" content="https://aws1.discourse-cdn.com/meteor/original/2X/7/71bba8fe7adcdbd04a6caf75f471f1adf00121aa.png">
  `);
});

Note that Blaze doesn’t support SSR, so it’s best to just skip it and append/alter the head directly

1 Like

Ohhh that looks very convincing and simplified.

Technically this would just append to the head no matter what else what in a template from blaze that had the head content?

@coagmano -

Ok I started this in testing and I’ve got it to “work”.

What I’m seeing is the onPageLoad that fires only fires when the page loads as it should. But when I browse the site it never fires again from the changing of routes.

How do I make this fire on route changes?

Social sites will scrape the url for image and description, so it’s only the initial page load that matters for them.

Otherwise, clientside route changes will have to be managed by flowrouter meta.

There might be an isomorphic package that can manage head content, but I don’t know one off the top of my head

You are correct this solved my problem. Tested, deployed, working. Thank you

1 Like