Best Practices SSR or ? for spiderable pages/facebook graph

Morning guys!

So I am trying to allow blog posts to be rendered to be spiderable by the facebook graph api. I have seen there are several ways to go about making this work, but none seem to stand out to me as the clear best way, though i am leaning towards server side rendering, but many of the things I have found online seem more difficult then I feel they should be.

What is the best way to put dynamic information into the page headers to be read by google/facebook ect… ?

My first solution was to put empty meta tags into my main.html file and then update them on the template render but the spiders seemingly only pickup the blank tags that way.

I have installed the phantomJS as an npm and I have the spiderable package listed so i thought it would automatically work, but unfortunately not the case.

What is the recommended/best way to accomplish my goal?

Hi Mike,

I have been working with dynamic head tags with this peace of code maybe it can help you with your task. I think you need Meteor 1.8 to be able to do this, not sure if it is available on 1.7. No need for phantomJS or anything else.

Be sure to load this on the server startup.

import SimpleSchema from 'simpl-schema';
import { onPageLoad } from 'meteor/server-render';

import { postsPublicQuery } from '../../api/posts/queries';


onPageLoad((sink) => {
  try {
    // TODO: Get your post id from the url path
    const postId = sink.request.url.path.split('/')?.[2];

    new SimpleSchema({
      postId: {
        type: SimpleSchema.RegEx.Id
      }
    }).validate({ condoId });

    // We need to get the post
    const post = postsPublicQuery.clone({ _id: postId }).fetchOne();

    if (post) {
      // TODO: I add other tags to head, but you can add the tags you want
      sink.appendToHead(`
      <link rel="manifest" href="/manifests/${condoId}.json">
      <link rel="apple-touch-icon" href="${condo?.icons?.x512 || '/images/icon_512.png'}">
    `);
    }
  } catch (error) {
    // Do something
  }
});
1 Like

I think if you are leaning towards SSR then it will mostly depend on your choice of view layer. With React and Helmet, this is a pretty simple thing to accomplish.

You are my number one Brokowski today brother man. Thank you! I did have to upgrade to 1.8 but this is the cake solution I was looking for.

1 Like