Google’s John Mueller suggests placing JavaScript code under the HTML header tag to ensure search crawlers can fully understand your site.
Mueller shares this advice in a Reddit thread where a user asks if HTML code placement could cause SEO issues.
The answer is yes; HTML code placement could negatively impact your SEO efforts if it doesn’t appear at the top of the page.
More precisely, it is important that the
– Section of the HTML document remains at the top of the page. This section should contain the information that Google needs to read your website properly.Any JavaScript code should be placed under the HTML headers.
To ensure that the JavaScript contains the section
doesn’t bother Mueller recommends using the rendering tool in Search Console:“The HTML headers (
) should be pretty much up. I would move each JS under the HTML headers and use the render tool in the search console to verify that the JS has the section.”
Regarding the main content, Mueller says its placement is less important, although it is crucial that the section
is clean and well organized so Googlebot can understand it properly.Mueller continues:
“It doesn’t matter that much for the content, but since the head stuff is for machine-readable information that’s proven to be in a certain part of the page, it has to be really clean at the top.
Down with JavaScript! (in the
)”
Why is JavaScript placement important for SEO?
When designing a website, it is best to place JavaScript code at the end of the HTML document, near the closing one -Insert tags.
That’s because JavaScript can delay rendering a webpage on load, resulting in a poor user experience.
By placing the JavaScript at the bottom of the page, the HTML code can be rendered first, allowing the user to view the content while the JavaScript loads in the background.
Additionally, you can prevent external JavaScript files from blocking page rendering by using the async or defer attributes.
source: Reddit
Featured image: StockEU/Shutterstock
var s_trigger_pixel_load = false; function s_trigger_pixel(){ if( !s_trigger_pixel_load ){ striggerEvent( 'load2' ); console.log('s_trigger_pix'); } s_trigger_pixel_load = true; } window.addEventListener( 'cmpready', s_trigger_pixel, false);
window.addEventListener( 'load2', function() {
if( sopp != 'yes' && !ss_u ){
!function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window,document,'script', 'https://connect.facebook.net/en_US/fbevents.js');
if( typeof sopp !== "undefined" && sopp === 'yes' ){ fbq('dataProcessingOptions', ['LDU'], 1, 1000); }else{ fbq('dataProcessingOptions', []); }
fbq('init', '1321385257908563');
fbq('track', 'PageView');
fbq('trackSingle', '1321385257908563', 'ViewContent', { content_name: 'googles-john-mueller-move-javascript-below-html-headers', content_category: 'news seo' }); } });