JavaScript & Search Engine Optimization (SEO)

There has been a lot of confusion over JavaScript and how it affects SEO efforts.  Some search engine optimization consultants or experts suggest not using JavaScript at all and some suggest minimal use.  Others will tell you that it is about where you place the JavaScript on the page.  The truth is that JavaScript does not have an adverse effect on SEO if used properly.

Before we go any further we should discuss how the search engines crawl a page and how JavaScript is used by most website developers.  When the search engines find a page it will see a mixture of content and code.  The idea behind good SEO strategy is to have a good ratio of content to code on the page.  Good SEO practices will also ensure that the search engines can find the relevant content quickly and easily.

Traditional website development usually calls for the JavaScript code to be placed at the top of the page.  This is more of a practice than a rule.  It actually does not matter where you place the JavaScript code on the page.  The required functionalities will work no matter where the code is placed.  As mentioned above, it is common practice for an SEO company to place the JavaScript code at the bottom of the page in order to allow the search engines to find the relevant content first.  The idea behind this is that when the spiders get to the page they do not have to sift through a bunch of code before they get to the content.  We must however keep in mind that the spiders will not stop once the find some content.  They will crawl the entire page until they come to the end.  That is why it is a good practice to have a solid balance between code and content.  Placing the code at the bottom of the page is fine but does not really guarantee that the page will be seen as more relevant.

A good solution to this which improves SEO and site speed is to create simple external JavaScript files where the code can be placed.  This file only contains the JavaScript and can include any related functions and style sheets.  When the JavaScript needs to be used for functionality throughout the site it is simply referred to in one small line of code on the page rather than having several long lines of code taking up space.  This saves the search engines time by not having to filter through the code and helps them focus on the keyword rich content.  It also decreases the overall length of the page which fosters faster crawling by the search engines.  It saves the user time because the externalized JavaScript files save bandwidth.  Pages load fatser and the user stays happy.

Using external JavaScript and CSS is great when you have certain functionalities repeated throughout the website.  They can be “called” upon once and simply refered to throughout a user’s time on the site.  Externalizing the code creates a higher ratio of SEO optimized content on the page.  The search engines can then focus on the title tags, mata tags, H1’s, and all the supportiing content without the distraction of extra code.

The bottom line though is that if the site is content rich, has a good struture for search engine optimization, and functions well it doesn’t matter too much where the JavaScript code is placed.  But to be safe, externalize the files and create a simpler, faster environment for the user and the search engines.

Leave a Reply