Can Google crawl dynamic content added in a window.onload() event?

by Luke   Last Updated September 11, 2019 14:04 PM

I inject some JSON-LD into a page dynamically via Javascript, when I test the page using Google's Structured Data Testing Tool, the expected output appears and I can see the Product Element is rendered.

However, if I defer loading of the script that is responsible for fetching the JSON-LD content and then call the function to inject it in a window "load" event listener, the content no longer appears in the Structured Data Testing Tool.

In short the testing tool shows my markup when I do this...

<script src=""></script>

But not when I do this.

<script src="" defer=""></script>
    window.addEventListener('load', (event) => {

I guess I'm asking whether this is a shortcoming in the Testing Tool or whether the defer / onload approach is a step too far in terms of Google being able to index the content.

Related Questions

Updated March 23, 2016 08:01 AM

Updated July 18, 2016 08:01 AM

Updated August 02, 2018 08:04 AM

Updated June 17, 2015 23:01 PM