DEV Community

seotto.com
seotto.com

Posted on

Is structured data injected by JavaScript good enough, or must JSON-LD be in the server HTML? Let's argue about it

Automated technical SEO checks that catch indexing blocks and deploy regressions — seotto.com

Structured data (usually a <script type="application/ld+json"> block describing a product, article, FAQ or organisation) can get onto a page in two very different ways.

Server-side: the JSON-LD is part of the HTML your server sends. View source, and it's there.

Client-side: the HTML arrives without it, and JavaScript adds it afterwards, from your app's components, or from a tag manager that marketing controls.

Google's documentation says it can process structured data added with JavaScript, as long as the page renders properly. So is it fine to inject it, or should it always be in the server response? Let's argue about it.

The case for JavaScript-injected structured data

Google handles it. Googlebot renders pages with a recent version of Chrome. If the script tag exists after rendering, it gets read. Google even documents generating structured data with JavaScript and tag managers.

It's often the only practical option. In a pure single-page app, everything is client-rendered anyway. Adding server-side rendering just for a JSON-LD block is a big project.

It decouples SEO from release cycles. With a tag manager, an SEO specialist can add or fix structured data without waiting for a deploy. For teams where engineering time is scarce, that's a real advantage.

The data is right there in the client. Product price, availability and reviews are often fetched by the front end. Building JSON-LD from the same state guarantees the markup matches what's on screen.

The case for server HTML only

Rendering is a second, later step. Google crawls the raw HTML first and renders later, when resources allow. Anything that only exists after rendering depends on that second step succeeding: scripts loading, APIs responding, no errors, within the renderer's time budget. Every one of those is a way to quietly lose the markup.

Not everyone renders. Many other crawlers, link-preview bots and AI crawlers read only the raw HTML. If your structured data matters beyond Google (and for things like organisation info and product data, it increasingly does), client-side markup is invisible to a lot of consumers.

Tag managers drift. JSON-LD defined in a tag manager isn't in version control, isn't reviewed with the code, and isn't tested by CI. The page template changes, the tag's selectors break, and the markup starts describing the wrong price, or nothing at all. These are some of the hardest regressions to notice.

Mismatches are risky. Structured data that disagrees with visible content (a price that's stale, a review count from yesterday) can lead to rich results being dropped or manual actions for misleading markup. Server-rendered markup built from the same data as the page is the easiest way to keep them in sync.

It's harder to test. Checking server HTML is a single curl. Checking client-injected markup needs a headless browser, a wait condition and an assumption about how long rendering takes.

Where I've landed

I'd draw the line like this:

  1. Anything you depend on for rich results goes in the server HTML. Product, Article, BreadcrumbList, Organization, Event, JobPosting. If losing it would cost you visible search features, render it on the server, from the same data as the page.
  2. Client-side injection is acceptable for experiments and gaps, as long as someone owns it and it's on a list to move server-side if it proves useful.
  3. Tag-manager markup gets the same review as code. Exported, in version control, with a named owner. Otherwise it's unmaintained code running on your production pages.
  4. Never do both for the same type. A server-rendered Product block plus a tag-manager Product block on the same page gives crawlers two different descriptions of the same thing.
  5. Test the raw HTML in CI. A check that the JSON-LD block exists, parses and contains the expected @type on one page per template catches most regressions before they ship.

Structured data tends to break silently: a template change, a tag manager edit, a renderer timeout. seotto.com keeps checking pages after deploys for technical SEO regressions, so markup that disappeared from the HTML doesn't sit unnoticed for weeks.

The parts I'm still unsure about

  • Frameworks with streaming or partial hydration. Some modern setups put JSON-LD in the initial HTML, some stream it later in the same response, some only add it on hydration. Is streamed-in-the-same-response "server HTML"? I think yes, but I'd test what each crawler actually receives.
  • Prices that change by the minute. If price changes faster than pages are cached, server markup can be stale too. Is a client-side update more accurate, or just inconsistent in a different way?
  • AI crawlers. It's not clear how much they use structured data, but they almost all read raw HTML only. If you care about that traffic, it's one more argument for the server side.

What about Google's own testing tools?

The Rich Results Test and URL Inspection both render JavaScript, so client-side markup passes them. That's useful, but it can be misleading: a passing test tells you Google can see the markup when rendering succeeds, not that every crawler sees it, or that rendering succeeds every time on every page. Treat a pass as "it works for Google in good conditions", and check the raw HTML for everything else.

A quick test for your site

Pick one URL per template and compare two things:

curl -s https://www.example.com/products/example | grep -c 'application/ld+json'
Enter fullscreen mode Exit fullscreen mode

against the count you see in the rendered page (DevTools Elements panel, or the URL Inspection tool's rendered HTML in Search Console). If the first number is lower, some of your structured data only exists after JavaScript runs, and now you know which side of this argument your site is on.

Related reading

Where does your structured data come from: templates, components, or a tag manager? And has client-side markup ever silently stopped working for you?

Top comments (0)