The 8 main ways JavaScript can impact SEO performance
Tags: seo, javascript
Published: 2019-10-17 09:19:22

JavaScript rendering is often a complicated and resource-intensive process, and can significantly impact a variety of different performance and user experience factors which SEO success depends on.

This is why it’s crucial to understand where these issues can occur and how they can impact your website.

Here are the 8 main things to watch out for within a JavaScript-powered website that can impact SEO performance:

<ol>
<li><b>Rendering speed</b></li>
<li><b>Main thread activity</b></li>
<li><b>Conflicting signals between HTML and JavaScript</b></li>
<li><b>Blocked scripts</b></li>
<li><b>Scripts in the head</b></li>
<li><b>Content duplication</b></li>
<li><b>User events</b></li>
<li><b>Service workers</b></li>
</ol>

<h2><b>1. Rendering speed</b></h2>
The process of rendering can be an expensive and strenuous process due to the different stages required to download, parse, compile and execute JavaScript. This causes significant issues when that work falls on a user’s browser or search engine crawler.

Having JavaScript-heavy pages that take a long time to process and render means that they are at risk of not being rendered or processed by search engines.

<blockquote>
“If your web server is unable to handle the volume of crawl requests for resources, it may have a negative impact on our capability to render your pages. If you’d like to ensure that your pages can be rendered by Google, make sure your servers are able to handle crawl requests for resources.”
</blockquote>
-[Google Webmaster Central Blog](https://webmasters.googleblog.com/2014/05/understanding-web-pages-better.html)

JavaScript that renders slowly will also impact your users because, with the increase of page load time, bounce rates will also rise. Nowadays a user will expect a page to load within a few seconds or less. However, getting a page that requires JavaScript rendering to load quickly enough to meet those expectations can be challenging.

![Page load speed vs bounce rate chart](https://thepracticaldev.s3.amazonaws.com/i/gzcpqq1xkcxskhchpodm.png)
<center>Source: [Think with Google](https://www.thinkwithgoogle.com/marketing-resources/data-measurement/mobile-page-speed-new-industry-benchmarks/)</center>

Another issue to consider is that a user’s device and CPU will usually have to do the hard work with JavaScript rendering, but not all CPUs are up for the challenge. It’s important to be aware that users will experience page load times differently depending on their device.

Just because a site appears to load quickly on a high-end phone, it doesn’t mean that this will be the case for a user accessing the same page with a lower-end phone.

<blockquote>
“What about a real-world site, like CNN.com? On the high-end iPhone 8 it takes just ~4s to parse/compile CNN’s JS compared to ~13s for an average phone (Moto G4). This can significantly impact how quickly a user can fully interact with this site.”
</blockquote>
-[Google Web Fundamentals](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/javascript-startup-optimization/)

![Chart showing JavaScript processing times for different devices](https://thepracticaldev.s3.amazonaws.com/i/n78zsuvdd46v2vuhe139.png)
<center>Source: [Google Developers](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/javascript-startup-optimization/)</center>

<h2><b>2. Main thread activity</h2></b>
JavaScript is single-threaded, meaning that the entire main thread is halted while JavaScript is parsed, compiled and executed. With this kind of setup, queues can form and bottlenecks can happen, meaning that the entire process of loading a page can be delayed and a search engine won't be able to see any content on the page until the scripts have been executed.

Delays within the main thread can significantly increase the time it takes to load a page for search engines, and for the page to become interactive for users, so avoid blocking main thread activity wherever possible.

Keep an eye on how many resources are being executed and where request timeouts are happening, as these can be some of the main culprits which create bottlenecks.

<h2><b>3. Conflicting signals between HTML and JavaScript</h2></b>
First impressions count with search engines, so make sure you’re giving them clear, straightforward instructions about your website in the HTML as soon as they come across the page.

Adding important meta tags using JavaScript rather than adding them in the HTML is advised against, because either Google won’t see these tags straight away because of its [delayed rendering process](https://dev.to/rachellcostello/how-search-engines-social-media-crawlers-render-javascript-438e), or other search engines won’t see them at all due to the fact that they can’t render.

All search engines will use the signals from the HTML in the initial fetch to determine crawling and indexing. Google and the few search engines that have rendering capabilities will then render pages at a later date, but if the signals served via JavaScript differ from what was initially found in the HTML, then this will contradict what the search engine has already been told about the page.

For example, if you use JavaScript to remove a robots meta tag like noindex, Google will have already seen the noindex tag in the HTML and won’t waste resources rendering a page it has been told not to include in its index. This means that the instructions to remove the noindex won’t even be seen as they’re hidden behind JavaScript which won’t be rendered in the first place.

Aim to include the most important tags and signals within the HTML where possible and make sure they’re not being altered by JavaScript. This includes page titles, content, hreflang and any other elements that are used for indexing.

<blockquote>
“The signals you provide via JavaScript shouldn't conflict with the ones in the HTML.”
</blockquote>
-John Mueller, [Google Webmaster Hangout](https://www.deepcrawl.com/blog/news/google-webmaster-hangout-notes-june-26th-2018/#13)

<h2><b>4. Blocked scripts</h2></b>
If a script is blocked, such as in the [robots.txt file](https://www.deepcrawl.com/knowledge/technical-seo-library/robots-txt/), this will impact how search engines will be able to see and understand a website. Scripts that are crucial to the layout and content of a page need to be accessible so that the page can be rendered properly.

<blockquote>
“Blocking scripts for Googlebot can impact its ability to render pages.”
</blockquote>
-John Mueller, [Google Webmaster Hangout](https://www.deepcrawl.com/blog/news/google-webmaster-hangout-notes-june-1st-2018/#1)

![Render-blocking scripts report in PageSpeed Insights](https://thepracticaldev.s3.amazonaws.com/i/sv31vdr34d2943r0blbh.png)
<center>Source: [PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights/)</center>

This is especially important for mobile devices, as search engines rely on being able to fetch external resources to be able to display mobile results correctly.

<blockquote>
“If resources like JavaScript or CSS in separate files are blocked (say, with robots.txt) so that Googlebot can’t retrieve them, our indexing systems won’t be able to see your site like an average user. This is especially important for mobile websites, where external resources like CSS and JavaScript help our algorithms understand that the pages are optimized for mobile.”
</blockquote>
-[Google Webmaster Central Blog](https://webmasters.googleblog.com/2014/05/understanding-web-pages-better.html)

<h2><b>5. Scripts in the head</h2></b>
When JavaScript is served in the head, this can delay the rendering and loading of the entire page. This is because everything in the head is loaded as a priority before the body can start to be loaded.

<blockquote>
“Don't serve critical JavaScript in the head as this can block rendering.”
</blockquote>
-John Mueller, [Google Webmaster Hangout](https://www.deepcrawl.com/blog/news/google-webmaster-hangout-notes-october-30th-2018/#6)

Serving JavaScript in the head is also advised against because it can cause search engines to ignore any other head tags below it. If Google sees a JavaScript tag within the contents of the head, it can assume that the body section has begun and ignore any other elements below it that were meant to be included in the head.

<blockquote>
“JavaScript snippets can close the head prematurely and cause any elements below to be overlooked.”
</blockquote>
-John Mueller, [Google Webmaster Hangout](https://www.deepcrawl.com/blog/news/google-webmaster-hangout-notes-october-19th-2018/#8)

<h2><b>6. Content duplication</h2></b>
JavaScript can cause duplication and canonicalisation issues when it is used to serve content. This is because if scripts take too long to process, then the content they generate won’t be seen.

This can cause Google to only see boilerplate, duplicate content across a site that experiences rendering issues, meaning that Google won’t be able to find any unique content to rank pages with. This can often be an issue for Single Page Applications (SPAs) where the content dynamically changes without having to reload the page.

Here are Google Webmaster Trends Analyst, [John Mueller’s thoughts on managing SPAs](https://www.reddit.com/r/TechSEO/comments/ag77vi/canonicals_and_angular_js/):

<blockquote>
“If you're using a SPA-type setup where the static HTML is mostly the same, and JavaScript has to be run in order to see any of the unique content, then if that JavaScript can't be executed properly, then the content ends up looking the same. This is probably a sign that it's too hard to get to your unique content -- it takes too many requests to load, the responses (in sum across the required requests) take too long to get back, so the focus stays on the boilerplate HTML rather than the JS-loaded content.”
</blockquote>

<h2><b>7. User events</h2></b>
JavaScript elements that require interactivity may work well for users, but they don’t for search engines. Search engines have a very different experience with JavaScript than a regular user.

This is because search engine bots can’t interact with a page in the same way that a human being would. They don’t click, scroll or select options from menus. Their main purpose is to discover and follow links to content that they can add to their index.

This means that any content that depends on JavaScript interactions to be generated won’t be indexed. For example, search engines will struggle to see any content hidden behind an [‘onclick’ event](https://www.w3schools.com/jsref/event_onclick.asp).

Another thing to bear in mind is that Googlebot and the other search engine crawlers clear cookies, local storage and session storage data after each page load, so this will be a problem for website owners who rely on cookies to serve any kind of personalised, unique content that they want to have indexed.

<blockquote>
“Any features that requires user consent are auto-declined by Googlebot.”
</blockquote>
-[Google Search](https://developers.google.com/search/docs/guides/rendering)

<h2><b>8. Service workers</h2></b>
A [service worker](https://developers.google.com/web/fundamentals/primers/service-workers/) is a script that works in the background of the browser and on a separate thread. Service workers can run pages and provide content based on their own memory, meaning they can work offline without the server being involved.

![Diagram showing how Service Workers work](https://thepracticaldev.s3.amazonaws.com/i/u6xcq8tomsqari3n6my9.png)
<center>Source: [Red Hat](https://developers.redhat.com/blog/2017/03/30/service-workers-in-the-browser-not-clerks-the-movie/)</center>

The benefit of using a service worker is that it decreases page load time because it doesn’t reload assets that aren’t needed. However, the issue is that Google and other search engine crawlers don’t support service workers.

The service worker can make it look like content is rendering correctly, but this may not be the case. Make sure your website and its key content still works properly without a service worker, and test your server configuration to avoid this issue.

Hopefully this guide has provided you with some new insights into the impact that JavaScript can have on SEO performance, as well as some areas that you can look into for the websites that you manage.