Last week, I reported on Google’s John Mueller’s comments about the HTML head section and why it should be kept clean. John posted his Mastodon thread on Friday detailing the head section and how search engines interact with it, especially when he contains a lot of JavaScript.
Here’s what the thread says:
SEO in your head vs too much #JavaScript?
This comes up from time to time, but I thought I’d elaborate once (it’s nothing new). Search engines (only Google and his YMMV know) render HTML pages and you need to find some settings at the top of the page to enable. If these settings bother you,
Fragile, ideally move these settings to the top of your head.
The SEO settings I’m thinking of are the robots meta tag and the canonical link element, but some people think the title and description meta tags are also important. Not only SEO but also charset definitions, viewports, CSP, etc. should be considered valid.
“Of course my head is fine” – sometimes not as obvious as clearly broken markup. head is self-closing, so an invalid HTML element is
The rest are considered body parts. It could be a stray img somewhere in the wrong place. It could be an iframe that the script inserts in the top of the head during rendering. This can be seen by inspecting the DOM of the page in a browser.
If you don’t want your page indexed, or want to use a different URL as canonical, you probably don’t want search engines to guess. (A big part of SEO is not letting search engines guess.)
In short, if you care about these SEO settings, avoid brittle heads, consider moving them to the top of your head (don’t include 5,000 lines of JS on top of that), and keep them rendered Double check the DOM in your browser. on time.
No need to move it to the body (which can cause other problems). Move under the key elements you need to discover in your head.
— John Mueller is hardly here 🐀 (@JohnMu) January 13, 2023
That’s the end of the thread in his head – get it?
Forum discussion on Mastodon.