Can you SEO JavaScript? A basic overview of JavaScript and SEO

Stephen McCance July 15, 2021

The short answer to “can you SEO JavaScript?”, is yes. However, as with many things in SEO, it’s not quite that simple! JavaScript can complicate SEO by making it difficult for Google to crawl and read a website, or render website elements properly. This is one of the primary reasons why JavaScript is considered bad for SEO. Here we look a little further into why this is the case, and what, if anything, can be done about it.

What Is JavaScript?

JavaScript is a coding language that is used to make web pages interactive. HTML and CSS are types of code used to give structure and style to a website, whereas JavaScript is commonly used by developers for items such as search bars, videos, drop downs, animations and refreshing feeds for social media. In short, it is used for many interactive components of web applications. JavaScript elements can be great for improving the UX (User Experience) on your website, which is where the conflict tends to arise. SEO nowadays puts User Experience front and centre, so how can JavaScript and SEO be in conflict if they have a shared aim?

Essentially, JavaScript, whilst currently the third most popular coding language out there, is old and dying out. After C and Python, JavaScript is up there slowly becoming a thing of the past for web development. So, as an “outdated” coding language, it’s usage is synonymous with old and sluggish elements of websites that could be easier for Google to work with if they were coded in something else, for example HTML5. One of the biggest debates over the last few years within the SEO industry, is ‘can Google effectively crawl and render JavaScript?’. There are various schools of thought here, with some people pointing to Google updates like this one as a means to prove that Google doesn’t hate JavaScript. Theoretically, this is correct, and Google has issued numerous pieces of guidance to say that they are “generally able” to crawl and render JavaScript in the same way as more modern browsers, but in practice the situation often paints a very different picture. The consensus is generally that its effectiveness varies depending on what exactly the JavaScript component is, and what framework has been used. For example, there’s a huge difference from Google’s perspective between Inline, External and Bundled JavaScript.

How Does JavaScript Affect SEO?

JavaScript can affect many on-page SEO elements: Rendered content, links, lazy-loaded images, page load times and even metadata. Some websites will embed content dynamically through the document object model (DOM) via JavaScript. Any content which is only rendered through users and not search engine bots will ultimately present issues with Google’s ability to take those components of your website into consideration when determining where it should rank. For example, if you’ve written fantastic, well-optimised content, but you’ve opted to present it inside animated JavaScript containers, it may look great but you can kiss goodbye to any benefit that content may have brought you in Google’s eyes. 9 times out of 10, it simply won’t be accounted for.

The most recent debate around the use of JavaScript has been centred on Google’s Core Web Vitals update coming into play, as they’ve made it clear that the respective scores directly affect your website rankings. Lazy loading images are highly recommended to improve load speeds, something that’s even more important than ever when looking at Core Web Vitals. One of the most common and efficient ways to implement lazy loading of images is to use JavaScript event tagging to dictate when images should begin loading. This is an example of when Google LIKES the use of JavaScript, and actually prefers its presence to not having it there (i.e. static images loading as usual on a page).

How Does Google Read SEO’d JavaScript 

First things first, it can take a long time crawling JavaScript, which is just one of the reasons that Google doesn’t like it as a general rule. The reason for this is because Google needs to go through a second rendering process to understand JavaScript, which isn’t necessary for other code. Google crawls JavaScript, as with everything else, in three steps:

  • Crawl 
  • Render
  • Index

This looks simple, but it isn’t when it comes to JavaScript. Google crawls all the basic coding on your website such as HTML first, then it comes back later to crawl the JavaScript, so anything that’s contained within the JavaScript is already being treated as of secondary importance. Once it has eventually been crawled, it then needs to be rendered, and here is where the debate comes in. Whilst there’s no official guidance from Google anymore to say that JavaScript can’t be rendered, it seems to have considerable amounts of difficulty in doing so in practice. Remember, seeing content in Google Cache doesn’t actually mean it’s been indexed by Google.

Does Google fully understand JavaScript? 

Google claims their algorithm does understand JavaScript, but they recommend using other forms of code where possible, and implementing things such as server-side rendering to make their job easier, suggesting the algorithm still has a difficult time in processing JavaScript – and we all know Google doesn’t like things it finds difficult.

What Can Make JavaScript More SEO Friendly? 

A good way to give Google a much easier job of crawling JavaScript is by implementing server-side rendering. Especially if you run off a full JavaScript-based web application. This does the dirty work for Google and crawls the HTML coding ready to present to Google in a neater, more streamlined way. But server side rendering also has its problems – namely that it makes everything more labour intensive. Every time you upload new content to your website, you will need to update the store version with your rendering cache, even if you’re just changing something minor. Publishers can also mirror all the pages on your site, meaning it can then cause duplicate content issues.

Another tip for JavaScript SEO is to make sure all your important metadata such as meta titles and meta descriptions are not on the pre-rendered side. The reason for this is because you want to make sure Google sees data properly when crawling JavaScript. The same goes for structured data. The key is to make sure Google has all of your relevant information that will help your site for rankings as quickly and easily as possible to give your site the best chance of ranking, in spite of having JavaScript components.

Summary

So, can you SEO JavaScript? Yes. Is it a massive pain to do? Also yes! It is recommended you try your best to avoid JavaScript in SEO for multiple reasons, ultimately it’s to prevent Google from missing key information when it comes to reading your content and determining where your site should rank.

If you can, avoid using JavaScript for SEO because of the complications involved with Google crawling JavaScript code and any content contained within it. It takes a lot of time to make sure Google reads all of your important information when using JavaScript and doing SEO. Ideally, stick to more streamlined and easily accessible coding such as HTML and CSS.

If you’re unsure as to whether your website contains restrictive JavaScript components that might negatively affect your SEO, get in touch and we would be happy to conduct a free review.

Back to Blog