I’m writing a package in order to poke around at some other aspects of Meteor development, and I’ve run into a roadblock. The end-goal is to insert a bit of dynamic JSON data into the <head> tag of an app. Doing this from the client is no big deal, since I can just call document.appendChild(), and then I can see it when I right-click and inspect the page from a browser.
But what I would really like is for it to append that data somehow before the page is rendered, from the server, so that I could right-click and ‘view page source’ and see it in the source code that’s delivered directly to the browser.
I got my fingers somewhat dirty pulling apart Build Plugins before realizing that it didn’t make sense a <head> tag from there, since the data is user-specific. It seems like Meteor.startup() inside the /server directory would be the logical place for it instead, but I don’t see how to append to the existing head if I don’t have access to document. Is there a way to do this from the server’s startup() method, or another route I should look into?
Thanks, @lassombra! After a bit of finagling, that was exactly what I was looking for. I’ll release the package in a day or two after I get my code cleaned up and tested a bit.
Though, you’re probably best using a package if you found one that works – I believe @arunoda was was going to change those meteorhacks packages to use dynamicHead internally at some point anyhow.
@abernix, that’s brilliant, and a way less hacky solution than I was about to implement. Inject-data offers a lot more flexibility as to exactly where the data is inserted (I could switch it to above head or below body with a small modification of the _hijackWriteIfNeeded() method, for example). But using dynamicHead is a whole lot smaller, and saves me from shipping a modified version of Picker alongside so that it doesn’t interfere with a user’s existing SSR package.