I have a script off site for a Schema (structured data). My Antiquated CMS does not recognize HTML5 and will modify Javascript in the html so I have to have it in a separate file. The problem is google does not find the external file. I read I should have it "dynamically injected into the page's contents" What is the best way to do this?
2 Answers
Well, I found it on my own. If anyone else has the same question:
<script>
var element = document.createElement("script");
element.setAttribute("src", "path-file.js");
document.getElementsByTagName("head")[0].appendChild(element);</script>
I'm a javascript novice so I had to research a bit. Works great.
-
While this works as far as the external file loads, search engines don't recognize the schema in this way, so it doesn't really solve my problem. Aug 16, 2018 at 21:18
Good to know you have already figured it out. But you can also insert JavaScript Code through Google Tag Manager instead of putting it at 3rd place externally, inject it through GTM.