rviscomi/capo.js

Scripts before meta data

simoncox opened this issue · 2 comments

Capo positions scripts before meta data.

There is an issue with that though. If a script in the head tag introduces a body tag - example with a Google Tam Manager script and advertiser could add in an <iframe> tag as part of their advert script for tracking, then when the page is read by Google (and probably other search engines) it will read the body tag and will assume it has reached the body and will from that point ignore any further head tags. This can lead to meta descriptions and canonicals being missed completely. My advice, because of this, has been to always put scripts last in the head unless you know what is in them - tag managers mean you will probably not.

But perhaps this is beyond the scope of this very good project!

Hey @simoncox. I think capo is doing the right thing here by recommending scripts before metadata as a general best practice. Of course, there may be circumstances where that might not be ideal, and it's ok to deviate from capo's recommendations.

It's also important to distinguish static vs dynamic validation. If the static head includes an invalid tag midway through, yes it will implicitly start the body and that will probably screw up how the rest of the contents get parsed. But if you have a script midway through the head and that dynamically injects some invalid markup like an iframe, I'm not so sure that it'll screw up the rest of the parsing. It probably depends on whether it's doing something like document.write in an synchronous script. I would expect GTM to do more dynamic injection if anything, but I could be wrong. Got any example pages where we could test this?

Sorry, not got any examples and it is kind of rare - probably because when it does happen its a limited advert run on a site and unluckily that the point where the page was crawled!

On reflection it is going to be up to me to point this out to site owners where they’re adding dynamic tags. Carry on, and ignore this!