javascriptasynchronousdeferreddeferred-executiondeferred-loading

Can the Google crawler read JSON-LD that is inserted after page load by a deferred script?


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?


Solution

  • 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.