2

I have a site where the content is pulled into the page via a JavaScript widget which is deferred, to make it non-blocking and to ensure the dependency scripts in the footer are loaded before the widget:

<script defer src="//my-server.com/my-widget.js"></script>

The widget also injects markup for Google structured data (JSON-LD) into the page, but I'm not seeing these results in the Google search results page. When I check the Rich Test Results tool using my page's URL I can see the JSON-LD markup isn't populated in the rendered page markup.

Google's own documentation says:

Google can read JSON-LD data when it is dynamically injected into the page's contents, such as by JavaScript code or embedded widgets in your content management system.

However it doesn't specify if this still works for scripts with defer or async attributes. I can't get it to work, but I need the widgets to execute asynchronously otherwise I get penalised in PageSpeed Insights for having blocking scripts. Has anyone found a solution?

Lewis Donovan
  • 889
  • 8
  • 19

1 Answers1

1

I think, you can't. Google engine will be read the schema right away after dom loaded. If you care about page speed and afraid that building of the ld+json schema takes too much time, you may consider using microdata instead of JSON-LD.

  • Thanks, that's helpful. There are some data that I want to include in the schema but not display on the page, is there a solution for this? – Lewis Donovan Feb 27 '20 at 10:39
  • 1
    @LewisDonovan sorry for late answer. Sure, you can. You can use `meta` tag if you want to have data but hidden it from page. See the last example on this [page](https://schema.org/docs/gs.html) However, be careful, if your micro data fundamentally different from what you display, Google engine may not like this and it will take action (in extreme cases, it may even put your site in black list) – Stanislau Listratsenka Mar 05 '20 at 08:05
  • Understood. Thanks for your help. – Lewis Donovan Mar 06 '20 at 14:17